Dynamically adding a stylesheet

Discussion in 'ASP .Net Building Controls' started by Nathan Sokalski, May 8, 2006.

  1. I want to dynamically add a stylesheet using <style type="text/css"></style>
    tags. The code that will use this stylesheet will be shared, so I will not
    have control over what the user does as far as stuff like adding
    runat="server" and id="someid" attributes to the <head> tag of their .aspx
    page. I was wondering if there is a way similar to the
    RegisterClientScriptBlock method that can be used. Any ideas or suggestions?
    Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
     
    Nathan Sokalski, May 8, 2006
    #1
    1. Advertising

  2. Actually, I believe you can get away with RegisterClientScriptBlock even
    though it is not "script". Try it.
    Peter

    --
    Co-founder, Eggheadcafe.com developer portal:
    http://www.eggheadcafe.com
    UnBlog:
    http://petesbloggerama.blogspot.com




    "Nathan Sokalski" wrote:

    > I want to dynamically add a stylesheet using <style type="text/css"></style>
    > tags. The code that will use this stylesheet will be shared, so I will not
    > have control over what the user does as far as stuff like adding
    > runat="server" and id="someid" attributes to the <head> tag of their .aspx
    > page. I was wondering if there is a way similar to the
    > RegisterClientScriptBlock method that can be used. Any ideas or suggestions?
    > Thanks.
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
    >
    >
     
    Peter Bromberg [C# MVP], May 9, 2006
    #2
    1. Advertising

  3. Thanks! It may not be the intended purpose, or even inside the <head> tag,
    but it's good enough for me, and it works.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Peter Bromberg [C# MVP]" <> wrote in message
    news:...
    > Actually, I believe you can get away with RegisterClientScriptBlock even
    > though it is not "script". Try it.
    > Peter
    >
    > --
    > Co-founder, Eggheadcafe.com developer portal:
    > http://www.eggheadcafe.com
    > UnBlog:
    > http://petesbloggerama.blogspot.com
    >
    >
    >
    >
    > "Nathan Sokalski" wrote:
    >
    >> I want to dynamically add a stylesheet using <style
    >> type="text/css"></style>
    >> tags. The code that will use this stylesheet will be shared, so I will
    >> not
    >> have control over what the user does as far as stuff like adding
    >> runat="server" and id="someid" attributes to the <head> tag of their
    >> .aspx
    >> page. I was wondering if there is a way similar to the
    >> RegisterClientScriptBlock method that can be used. Any ideas or
    >> suggestions?
    >> Thanks.
    >> --
    >> Nathan Sokalski
    >>
    >> http://www.nathansokalski.com/
    >>
    >>
    >>
     
    Nathan Sokalski, May 9, 2006
    #3
  4. I cheat. I've got two repeaters defined in my masterpages, one for
    scripts, one for CSS. My base page class has a couple of List<string>'s
    and I just call
    AddResource("path/to/file", ResourceType.Css) to add resources to those
    Lists

    Then I bind the repeaters on PreRender so any page events have an
    opportunity to add CSS/Js that'll be needed on the client. It's a hack,
    but I like my stylesheets and scripts in external files referenced in
    the head where they belong.
     
    Flinky Wisty Pomm, May 9, 2006
    #4
  5. I don't get it but <%= ... > should do??
    I'm using it for resolving the script url.


    "Nathan Sokalski" <> schreef in bericht
    news:...
    >I want to dynamically add a stylesheet using <style
    >type="text/css"></style> tags. The code that will use this stylesheet will
    >be shared, so I will not have control over what the user does as far as
    >stuff like adding runat="server" and id="someid" attributes to the <head>
    >tag of their .aspx page. I was wondering if there is a way similar to the
    >RegisterClientScriptBlock method that can be used. Any ideas or
    >suggestions? Thanks.
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
     
    Edwin Knoppert, May 9, 2006
    #5
  6. <%=...%> would be fine if I was writing the webform that used the
    stylesheet, but I am not writing the webform, I am writing a couple external
    classes that will be used with webforms.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Edwin Knoppert" <> wrote in message
    news:4460b513$0$2022$...
    >I don't get it but <%= ... > should do??
    > I'm using it for resolving the script url.
    >
    >
    > "Nathan Sokalski" <> schreef in bericht
    > news:...
    >>I want to dynamically add a stylesheet using <style
    >>type="text/css"></style> tags. The code that will use this stylesheet will
    >>be shared, so I will not have control over what the user does as far as
    >>stuff like adding runat="server" and id="someid" attributes to the <head>
    >>tag of their .aspx page. I was wondering if there is a way similar to the
    >>RegisterClientScriptBlock method that can be used. Any ideas or
    >>suggestions? Thanks.
    >> --
    >> Nathan Sokalski
    >>
    >> http://www.nathansokalski.com/
    >>

    >
    >
     
    Nathan Sokalski, May 9, 2006
    #6
  7. Nathan Sokalski

    Martijn Saly Guest

    Flinky Wisty Pomm wrote:
    > I cheat. I've got two repeaters defined in my masterpages, one for
    > scripts, one for CSS. My base page class has a couple of List<string>'s
    > and I just call
    > AddResource("path/to/file", ResourceType.Css) to add resources to those
    > Lists
    >
    > Then I bind the repeaters on PreRender so any page events have an
    > opportunity to add CSS/Js that'll be needed on the client. It's a hack,
    > but I like my stylesheets and scripts in external files referenced in
    > the head where they belong.
    >


    That sounds like a much better solution. A <script> tag inside the body is
    ugly (and invalid XHTML, I believe). And a <style> tag in the body is just
    invalid in both HTML and XHTML.

    And we all know that production-quality controls generate valid XHTML at
    least, right? ;)

    --
    Thanks,

    Martijn Saly
     
    Martijn Saly, May 10, 2006
    #7
  8. Nathan Sokalski

    MSDN Guest

    Flinky Wisty Pomm,

    Can you please show an example.
    why repeaters...>???

    Thank you,

    Sa


    "Flinky Wisty Pomm" <> wrote in message
    news:...
    >I cheat. I've got two repeaters defined in my masterpages, one for
    > scripts, one for CSS. My base page class has a couple of List<string>'s
    > and I just call
    > AddResource("path/to/file", ResourceType.Css) to add resources to those
    > Lists
    >
    > Then I bind the repeaters on PreRender so any page events have an
    > opportunity to add CSS/Js that'll be needed on the client. It's a hack,
    > but I like my stylesheets and scripts in external files referenced in
    > the head where they belong.
    >
     
    MSDN, May 12, 2006
    #8
  9. Nathan Sokalski

    Kris Guest

    Kris, Jul 8, 2006
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?ISO-8859-1?Q?J=F8rn_Tommy_Kinder=E5s?=

    Stylesheet referanse i stylesheet

    =?ISO-8859-1?Q?J=F8rn_Tommy_Kinder=E5s?=, Jul 3, 2004, in forum: XML
    Replies:
    3
    Views:
    616
    =?ISO-8859-1?Q?J=F8rn_Tommy_Kinder=E5s?=
    Jul 4, 2004
  2. Steven An
    Replies:
    1
    Views:
    541
    Martin Honnen
    Nov 23, 2004
  3. David Blickstein
    Replies:
    3
    Views:
    1,089
    David Blickstein
    Aug 2, 2005
  4. Nathan Sokalski

    Dynamically adding a stylesheet

    Nathan Sokalski, May 8, 2006, in forum: ASP .Net
    Replies:
    8
    Views:
    4,488
  5. Nathan Sokalski

    Dynamically adding a stylesheet

    Nathan Sokalski, May 8, 2006, in forum: ASP .Net Web Controls
    Replies:
    8
    Views:
    207
Loading...

Share This Page