Usercontrol, add styles via Page.Header.Attributes ?

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default Usercontrol, add styles via Page.Header.Attributes ?

    I want to add styles to the current page from within a usercontrol the
    correct(better) way.
    So i would like to insert the styles in the page head.

    Any good approach?


    Edwin Knoppert Guest

  2. Similar Questions and Discussions

    1. #24095 [Com]: phpinfo styles override page styles and damage appearance
      ID: 24095 Comment by: joe at monkeydepartment dot com Reported By: generic at thetahat dot com Status: Open...
    2. Flex 1.5 Header Renderer styles question
      I am having a great deal of trouble setting individual header properties in a DataGrid. I have tried multiple approaches with this to no avail. ...
    3. attributes to ListItemType.Header
      I want to add tooltexttips to a datagrids column headers. The code below handles BoundColumn but not TemplateColumn - and I can't figure out how to...
    4. Getting data from a usercontrol before containing page ends its page load
      How do I load a user control in a web form first, so that the web form's page_load acts according to events on the user control? In my code...
    5. Setting HTTP Header Attributes
      Hello, I am writing an application that makes a number of web service calls to a variety of sources and aggregates the data back on a web page. ...
  3. #2

    Default Re: Usercontrol, add styles via Page.Header.Attributes ?

    "Edwin Knoppert" <news@hellobasic.com> wrote in message
    news:457682ef$0$2017$ba620dc5@text.nova.planet.nl. ..
    >I want to add styles to the current page from within a usercontrol the
    >correct(better) way.
    > So i would like to insert the styles in the page head.
    >
    > Any good approach?
    I would recommend against this, unless the only purpose of the user control
    is to change styles. In general, the page should set the styles, not the
    controls.

    John


    John Saunders Guest

  4. #3

    Default Re: Usercontrol, add styles via Page.Header.Attributes ?

    I need specific styles for controls inside a gridview template.
    Since these are ASP.NET controls they expect a classname, not one or more
    styles.
    (Which can be set via code as well)

    I have > 8 styles to set, so alternatives are pretty cumbersome imo.
    (We keep the server working this way, instead of the client's browser only)



    "John Saunders" <john.saunders at trizetto.com> schreef in bericht
    news:%23fwKaJTGHHA.320@TK2MSFTNGP06.phx.gbl...
    > "Edwin Knoppert" <news@hellobasic.com> wrote in message
    > news:457682ef$0$2017$ba620dc5@text.nova.planet.nl. ..
    >>I want to add styles to the current page from within a usercontrol the
    >>correct(better) way.
    >> So i would like to insert the styles in the page head.
    >>
    >> Any good approach?
    >
    > I would recommend against this, unless the only purpose of the user
    > control is to change styles. In general, the page should set the styles,
    > not the controls.
    >
    > John
    >
    >

    Edwin Knoppert Guest

  5. #4

    Default Re: Usercontrol, add styles via Page.Header.Attributes ?

    "Edwin Knoppert" <news@hellobasic.com> wrote in message
    news:4576c3e3$0$2026$ba620dc5@text.nova.planet.nl. ..
    >I need specific styles for controls inside a gridview template.
    > Since these are ASP.NET controls they expect a classname, not one or more
    > styles.
    > (Which can be set via code as well)
    >
    > I have > 8 styles to set, so alternatives are pretty cumbersome imo.
    > (We keep the server working this way, instead of the client's browser
    > only)
    I don't understand your problem. We also use CSS classes very heavily. We
    have our controls reference the classes via CssClass on a server control or
    "class" on a client tag. We then have the pages reference the .css files
    containing the definitions of the classes. We have a base page class which
    emits the correct <link> tags on every page. This works well, without a
    control attempting to set styles for the page (which is a lot like the tail
    wagging the dog).

    John


    John Saunders Guest

  6. #5

    Default Re: Usercontrol, add styles via Page.Header.Attributes ?

    First, i'm not sure i posted this in the correct group, there is a
    webcontrols group as well, my current problem applies to a custom control
    for asp.net (therefore the styles of course :) )

    --------

    The idea is that i would like to prepare self-contained controls and
    therefore i don't prefer seperate css files.
    I was wrong yesterday by mentioning using the server tag for each control to
    add styles dynamically to each control.
    I just put a styles section directly into my usercontrol html part, it works
    but it's not recommended.
    Styles should be in the head and preferrable as include.
    Well i know that there are webresources but my knowledge about this all is
    not that far yet + the usercontrol is not a compiled control since it still
    depends to much on the project.
    (Like database tables and fields etc + there is no need)
    Therefore i choose for styles in the html, the easy way..

    I'm just figuring out how to deal with things, it's not all that trivial.

    And then there is the problem of recurring insertions, meaning multiple
    instances of my usercontrol on the same page would then insert duplicate
    styles (and javascript code) with the same name(s).

    For js there is this asp.net solution to register functionality which
    results into one codeblock on multiple inserts.
    Maybe this is also available with styles??

    There are several solutions, i'm working slowly to a better approach with
    respect to the complete control, not only this styles issue.
    Most of my usercontrols are never required outside the project, it would
    cost to much time to make them stand-alone anyway.



    "John Saunders" <john.saunders at trizetto.com> schreef in bericht
    news:uU6jB4fGHHA.4688@TK2MSFTNGP04.phx.gbl...
    > "Edwin Knoppert" <news@hellobasic.com> wrote in message
    > news:4576c3e3$0$2026$ba620dc5@text.nova.planet.nl. ..
    >>I need specific styles for controls inside a gridview template.
    >> Since these are ASP.NET controls they expect a classname, not one or more
    >> styles.
    >> (Which can be set via code as well)
    >>
    >> I have > 8 styles to set, so alternatives are pretty cumbersome imo.
    >> (We keep the server working this way, instead of the client's browser
    >> only)
    >
    > I don't understand your problem. We also use CSS classes very heavily. We
    > have our controls reference the classes via CssClass on a server control
    > or "class" on a client tag. We then have the pages reference the .css
    > files containing the definitions of the classes. We have a base page class
    > which emits the correct <link> tags on every page. This works well,
    > without a control attempting to set styles for the page (which is a lot
    > like the tail wagging the dog).
    >
    > John
    >
    >

    Edwin Knoppert Guest

  7. #6

    Default Re: Usercontrol, add styles via Page.Header.Attributes ?

    I have used RegisterStartupScript to inject styles into a web page from a
    custom control - just specify that the surrounding script tags should not be
    generated.
    This does stick the style data at the bottom of the page ( right before the
    </form> tag I beleive ) but I haven't seen any browsers so far that had any
    problem with style blocks outside of the head block.

    Gerry

    "Edwin Knoppert" <news@hellobasic.com> wrote in message
    news:45781583$0$2026$ba620dc5@text.nova.planet.nl. ..
    > First, i'm not sure i posted this in the correct group, there is a
    > webcontrols group as well, my current problem applies to a custom control
    > for asp.net (therefore the styles of course :) )
    >
    > --------
    >
    > The idea is that i would like to prepare self-contained controls and
    > therefore i don't prefer seperate css files.
    > I was wrong yesterday by mentioning using the server tag for each control
    > to add styles dynamically to each control.
    > I just put a styles section directly into my usercontrol html part, it
    > works but it's not recommended.
    > Styles should be in the head and preferrable as include.
    > Well i know that there are webresources but my knowledge about this all is
    > not that far yet + the usercontrol is not a compiled control since it
    > still depends to much on the project.
    > (Like database tables and fields etc + there is no need)
    > Therefore i choose for styles in the html, the easy way..
    >
    > I'm just figuring out how to deal with things, it's not all that trivial.
    >
    > And then there is the problem of recurring insertions, meaning multiple
    > instances of my usercontrol on the same page would then insert duplicate
    > styles (and javascript code) with the same name(s).
    >
    > For js there is this asp.net solution to register functionality which
    > results into one codeblock on multiple inserts.
    > Maybe this is also available with styles??
    >
    > There are several solutions, i'm working slowly to a better approach with
    > respect to the complete control, not only this styles issue.
    > Most of my usercontrols are never required outside the project, it would
    > cost to much time to make them stand-alone anyway.
    >
    >
    >
    > "John Saunders" <john.saunders at trizetto.com> schreef in bericht
    > news:uU6jB4fGHHA.4688@TK2MSFTNGP04.phx.gbl...
    >> "Edwin Knoppert" <news@hellobasic.com> wrote in message
    >> news:4576c3e3$0$2026$ba620dc5@text.nova.planet.nl. ..
    >>>I need specific styles for controls inside a gridview template.
    >>> Since these are ASP.NET controls they expect a classname, not one or
    >>> more styles.
    >>> (Which can be set via code as well)
    >>>
    >>> I have > 8 styles to set, so alternatives are pretty cumbersome imo.
    >>> (We keep the server working this way, instead of the client's browser
    >>> only)
    >>
    >> I don't understand your problem. We also use CSS classes very heavily. We
    >> have our controls reference the classes via CssClass on a server control
    >> or "class" on a client tag. We then have the pages reference the .css
    >> files containing the definitions of the classes. We have a base page
    >> class which emits the correct <link> tags on every page. This works well,
    >> without a control attempting to set styles for the page (which is a lot
    >> like the tail wagging the dog).
    >>
    >> John
    >>
    >>
    >
    >

    gerry Guest

  8. #7

    Default Re: Usercontrol, add styles via Page.Header.Attributes ?

    just a note
    after that last post i wondered why I had used RegisterStartupScript as
    opposed to RegisterClientScriptBlock
    so I made the change to RegisterClientScriptBlock
    this works just as well , the only difference is that the block is inserted
    at the top of the page just below the viewstate div.

    Gerry

    "gerry" <germ@canada.com> wrote in message
    news:Ob6hSqgGHHA.5020@TK2MSFTNGP03.phx.gbl...
    >I have used RegisterStartupScript to inject styles into a web page from a
    >custom control - just specify that the surrounding script tags should not
    >be generated.
    > This does stick the style data at the bottom of the page ( right before
    > the </form> tag I beleive ) but I haven't seen any browsers so far that
    > had any problem with style blocks outside of the head block.
    >
    > Gerry
    >
    > "Edwin Knoppert" <news@hellobasic.com> wrote in message
    > news:45781583$0$2026$ba620dc5@text.nova.planet.nl. ..
    >> First, i'm not sure i posted this in the correct group, there is a
    >> webcontrols group as well, my current problem applies to a custom control
    >> for asp.net (therefore the styles of course :) )
    >>
    >> --------
    >>
    >> The idea is that i would like to prepare self-contained controls and
    >> therefore i don't prefer seperate css files.
    >> I was wrong yesterday by mentioning using the server tag for each control
    >> to add styles dynamically to each control.
    >> I just put a styles section directly into my usercontrol html part, it
    >> works but it's not recommended.
    >> Styles should be in the head and preferrable as include.
    >> Well i know that there are webresources but my knowledge about this all
    >> is not that far yet + the usercontrol is not a compiled control since it
    >> still depends to much on the project.
    >> (Like database tables and fields etc + there is no need)
    >> Therefore i choose for styles in the html, the easy way..
    >>
    >> I'm just figuring out how to deal with things, it's not all that trivial.
    >>
    >> And then there is the problem of recurring insertions, meaning multiple
    >> instances of my usercontrol on the same page would then insert duplicate
    >> styles (and javascript code) with the same name(s).
    >>
    >> For js there is this asp.net solution to register functionality which
    >> results into one codeblock on multiple inserts.
    >> Maybe this is also available with styles??
    >>
    >> There are several solutions, i'm working slowly to a better approach with
    >> respect to the complete control, not only this styles issue.
    >> Most of my usercontrols are never required outside the project, it would
    >> cost to much time to make them stand-alone anyway.
    >>
    >>
    >>
    >> "John Saunders" <john.saunders at trizetto.com> schreef in bericht
    >> news:uU6jB4fGHHA.4688@TK2MSFTNGP04.phx.gbl...
    >>> "Edwin Knoppert" <news@hellobasic.com> wrote in message
    >>> news:4576c3e3$0$2026$ba620dc5@text.nova.planet.nl. ..
    >>>>I need specific styles for controls inside a gridview template.
    >>>> Since these are ASP.NET controls they expect a classname, not one or
    >>>> more styles.
    >>>> (Which can be set via code as well)
    >>>>
    >>>> I have > 8 styles to set, so alternatives are pretty cumbersome imo.
    >>>> (We keep the server working this way, instead of the client's browser
    >>>> only)
    >>>
    >>> I don't understand your problem. We also use CSS classes very heavily.
    >>> We have our controls reference the classes via CssClass on a server
    >>> control or "class" on a client tag. We then have the pages reference the
    >>> .css files containing the definitions of the classes. We have a base
    >>> page class which emits the correct <link> tags on every page. This works
    >>> well, without a control attempting to set styles for the page (which is
    >>> a lot like the tail wagging the dog).
    >>>
    >>> John
    >>>
    >>>
    >>
    >>
    >
    >

    gerry Guest

  9. #8

    Default Re: Usercontrol, add styles via Page.Header.Attributes ?

    Hmm, we might need some more fokes over here :)

    RegisterStartupScript, well i don't know all these Register.. stuff yet, but
    there are a few afaik.
    Of course, there is still the issue of duplicated (multiple) styles with the
    same name.
    I was wondering if some how we could make this more unique, i can.. manually
    but maybe the system offers better stuff.



    "gerry" <germ@canada.com> schreef in bericht
    news:uWBsA1gGHHA.3780@TK2MSFTNGP02.phx.gbl...
    > just a note
    > after that last post i wondered why I had used RegisterStartupScript as
    > opposed to RegisterClientScriptBlock
    > so I made the change to RegisterClientScriptBlock
    > this works just as well , the only difference is that the block is
    > inserted at the top of the page just below the viewstate div.
    >
    > Gerry
    >
    > "gerry" <germ@canada.com> wrote in message
    > news:Ob6hSqgGHHA.5020@TK2MSFTNGP03.phx.gbl...
    >>I have used RegisterStartupScript to inject styles into a web page from a
    >>custom control - just specify that the surrounding script tags should not
    >>be generated.
    >> This does stick the style data at the bottom of the page ( right before
    >> the </form> tag I beleive ) but I haven't seen any browsers so far that
    >> had any problem with style blocks outside of the head block.
    >>
    >> Gerry
    >>
    >> "Edwin Knoppert" <news@hellobasic.com> wrote in message
    >> news:45781583$0$2026$ba620dc5@text.nova.planet.nl. ..
    >>> First, i'm not sure i posted this in the correct group, there is a
    >>> webcontrols group as well, my current problem applies to a custom
    >>> control for asp.net (therefore the styles of course :) )
    >>>
    >>> --------
    >>>
    >>> The idea is that i would like to prepare self-contained controls and
    >>> therefore i don't prefer seperate css files.
    >>> I was wrong yesterday by mentioning using the server tag for each
    >>> control to add styles dynamically to each control.
    >>> I just put a styles section directly into my usercontrol html part, it
    >>> works but it's not recommended.
    >>> Styles should be in the head and preferrable as include.
    >>> Well i know that there are webresources but my knowledge about this all
    >>> is not that far yet + the usercontrol is not a compiled control since it
    >>> still depends to much on the project.
    >>> (Like database tables and fields etc + there is no need)
    >>> Therefore i choose for styles in the html, the easy way..
    >>>
    >>> I'm just figuring out how to deal with things, it's not all that
    >>> trivial.
    >>>
    >>> And then there is the problem of recurring insertions, meaning multiple
    >>> instances of my usercontrol on the same page would then insert duplicate
    >>> styles (and javascript code) with the same name(s).
    >>>
    >>> For js there is this asp.net solution to register functionality which
    >>> results into one codeblock on multiple inserts.
    >>> Maybe this is also available with styles??
    >>>
    >>> There are several solutions, i'm working slowly to a better approach
    >>> with respect to the complete control, not only this styles issue.
    >>> Most of my usercontrols are never required outside the project, it would
    >>> cost to much time to make them stand-alone anyway.
    >>>
    >>>
    >>>
    >>> "John Saunders" <john.saunders at trizetto.com> schreef in bericht
    >>> news:uU6jB4fGHHA.4688@TK2MSFTNGP04.phx.gbl...
    >>>> "Edwin Knoppert" <news@hellobasic.com> wrote in message
    >>>> news:4576c3e3$0$2026$ba620dc5@text.nova.planet.nl. ..
    >>>>>I need specific styles for controls inside a gridview template.
    >>>>> Since these are ASP.NET controls they expect a classname, not one or
    >>>>> more styles.
    >>>>> (Which can be set via code as well)
    >>>>>
    >>>>> I have > 8 styles to set, so alternatives are pretty cumbersome imo.
    >>>>> (We keep the server working this way, instead of the client's browser
    >>>>> only)
    >>>>
    >>>> I don't understand your problem. We also use CSS classes very heavily.
    >>>> We have our controls reference the classes via CssClass on a server
    >>>> control or "class" on a client tag. We then have the pages reference
    >>>> the .css files containing the definitions of the classes. We have a
    >>>> base page class which emits the correct <link> tags on every page. This
    >>>> works well, without a control attempting to set styles for the page
    >>>> (which is a lot like the tail wagging the dog).
    >>>>
    >>>> John
    >>>>
    >>>>
    >>>
    >>>
    >>
    >>
    >
    >

    Edwin Knoppert Guest

  10. #9

    Default Re: Usercontrol, add styles via Page.Header.Attributes ?

    i'm not sure if this what you mean by 'duplicate styles' or 'more unique'
    but you can ensure that a style block is included only once in the page by
    using IsClientScriptBlockRegistered before calling RegisterClientScriptBlock

    as far as not knowing 'all these Register stuff yet' the docs are a
    wonderful thing and google is just a click away



    "Edwin Knoppert" <news@hellobasic.com> wrote in message
    news:45784053$0$13604$ba620dc5@text.nova.planet.nl ...
    > Hmm, we might need some more fokes over here :)
    >
    > RegisterStartupScript, well i don't know all these Register.. stuff yet,
    > but there are a few afaik.
    > Of course, there is still the issue of duplicated (multiple) styles with
    > the same name.
    > I was wondering if some how we could make this more unique, i can..
    > manually but maybe the system offers better stuff.
    >
    >
    >
    > "gerry" <germ@canada.com> schreef in bericht
    > news:uWBsA1gGHHA.3780@TK2MSFTNGP02.phx.gbl...
    >> just a note
    >> after that last post i wondered why I had used RegisterStartupScript as
    >> opposed to RegisterClientScriptBlock
    >> so I made the change to RegisterClientScriptBlock
    >> this works just as well , the only difference is that the block is
    >> inserted at the top of the page just below the viewstate div.
    >>
    >> Gerry
    >>
    >> "gerry" <germ@canada.com> wrote in message
    >> news:Ob6hSqgGHHA.5020@TK2MSFTNGP03.phx.gbl...
    >>>I have used RegisterStartupScript to inject styles into a web page from a
    >>>custom control - just specify that the surrounding script tags should not
    >>>be generated.
    >>> This does stick the style data at the bottom of the page ( right before
    >>> the </form> tag I beleive ) but I haven't seen any browsers so far that
    >>> had any problem with style blocks outside of the head block.
    >>>
    >>> Gerry
    >>>
    >>> "Edwin Knoppert" <news@hellobasic.com> wrote in message
    >>> news:45781583$0$2026$ba620dc5@text.nova.planet.nl. ..
    >>>> First, i'm not sure i posted this in the correct group, there is a
    >>>> webcontrols group as well, my current problem applies to a custom
    >>>> control for asp.net (therefore the styles of course :) )
    >>>>
    >>>> --------
    >>>>
    >>>> The idea is that i would like to prepare self-contained controls and
    >>>> therefore i don't prefer seperate css files.
    >>>> I was wrong yesterday by mentioning using the server tag for each
    >>>> control to add styles dynamically to each control.
    >>>> I just put a styles section directly into my usercontrol html part, it
    >>>> works but it's not recommended.
    >>>> Styles should be in the head and preferrable as include.
    >>>> Well i know that there are webresources but my knowledge about this all
    >>>> is not that far yet + the usercontrol is not a compiled control since
    >>>> it still depends to much on the project.
    >>>> (Like database tables and fields etc + there is no need)
    >>>> Therefore i choose for styles in the html, the easy way..
    >>>>
    >>>> I'm just figuring out how to deal with things, it's not all that
    >>>> trivial.
    >>>>
    >>>> And then there is the problem of recurring insertions, meaning multiple
    >>>> instances of my usercontrol on the same page would then insert
    >>>> duplicate styles (and javascript code) with the same name(s).
    >>>>
    >>>> For js there is this asp.net solution to register functionality which
    >>>> results into one codeblock on multiple inserts.
    >>>> Maybe this is also available with styles??
    >>>>
    >>>> There are several solutions, i'm working slowly to a better approach
    >>>> with respect to the complete control, not only this styles issue.
    >>>> Most of my usercontrols are never required outside the project, it
    >>>> would cost to much time to make them stand-alone anyway.
    >>>>
    >>>>
    >>>>
    >>>> "John Saunders" <john.saunders at trizetto.com> schreef in bericht
    >>>> news:uU6jB4fGHHA.4688@TK2MSFTNGP04.phx.gbl...
    >>>>> "Edwin Knoppert" <news@hellobasic.com> wrote in message
    >>>>> news:4576c3e3$0$2026$ba620dc5@text.nova.planet.nl. ..
    >>>>>>I need specific styles for controls inside a gridview template.
    >>>>>> Since these are ASP.NET controls they expect a classname, not one or
    >>>>>> more styles.
    >>>>>> (Which can be set via code as well)
    >>>>>>
    >>>>>> I have > 8 styles to set, so alternatives are pretty cumbersome imo.
    >>>>>> (We keep the server working this way, instead of the client's browser
    >>>>>> only)
    >>>>>
    >>>>> I don't understand your problem. We also use CSS classes very heavily.
    >>>>> We have our controls reference the classes via CssClass on a server
    >>>>> control or "class" on a client tag. We then have the pages reference
    >>>>> the .css files containing the definitions of the classes. We have a
    >>>>> base page class which emits the correct <link> tags on every page.
    >>>>> This works well, without a control attempting to set styles for the
    >>>>> page (which is a lot like the tail wagging the dog).
    >>>>>
    >>>>> John
    >>>>>
    >>>>>
    >>>>
    >>>>
    >>>
    >>>
    >>
    >>
    >
    >

    gerry Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139