Dynamically adding a stylesheet

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nathan Sokalski

    #1

    Dynamically adding a stylesheet

    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
    RegisterClientS criptBlock method that can be used. Any ideas or suggestions?
    Thanks.
    --
    Nathan Sokalski
    njsokalski@hotm ail.com
    有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。



  • Peter Bromberg [C# MVP]

    #2
    RE: Dynamically adding a stylesheet

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

    --
    Co-founder, Eggheadcafe.com developer portal:

    UnBlog:





    "Nathan Sokalski" wrote:
    [color=blue]
    > 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
    > RegisterClientS criptBlock method that can be used. Any ideas or suggestions?
    > Thanks.
    > --
    > Nathan Sokalski
    > njsokalski@hotm ail.com
    > http://www.nathansokalski.com/
    >
    >
    >[/color]

    Comment

    • Nathan Sokalski

      #3
      Re: Dynamically adding a stylesheet

      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
      njsokalski@hotm ail.com
      有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。


      "Peter Bromberg [C# MVP]" <pbromberg@yaho o.nospammin.com > wrote in message
      news:05979FBF-CEE3-46B4-9E23-A10A92FFDA94@mi crosoft.com...[color=blue]
      > Actually, I believe you can get away with RegisterClientS criptBlock 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:
      >[color=green]
      >> 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
      >> RegisterClientS criptBlock method that can be used. Any ideas or
      >> suggestions?
      >> Thanks.
      >> --
      >> Nathan Sokalski
      >> njsokalski@hotm ail.com
      >> http://www.nathansokalski.com/
      >>
      >>
      >>[/color][/color]


      Comment

      • Flinky Wisty Pomm

        #4
        Re: Dynamically adding a stylesheet

        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("pa th/to/file", ResourceType.Cs s) 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.

        Comment

        • Edwin Knoppert

          #5
          Re: Dynamically adding a stylesheet

          I don't get it but <%= ... > should do??
          I'm using it for resolving the script url.


          "Nathan Sokalski" <njsokalski@hot mail.com> schreef in bericht
          news:OBpEhuucGH A.5048@TK2MSFTN GP03.phx.gbl...[color=blue]
          >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
          >RegisterClient ScriptBlock method that can be used. Any ideas or
          >suggestions? Thanks.
          > --
          > Nathan Sokalski
          > njsokalski@hotm ail.com
          > http://www.nathansokalski.com/
          >[/color]


          Comment

          • Nathan Sokalski

            #6
            Re: Dynamically adding a stylesheet

            <%=...%> 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
            njsokalski@hotm ail.com
            有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。


            "Edwin Knoppert" <news@hellobasi c.com> wrote in message
            news:4460b513$0 $2022$ba620dc5@ text.nova.plane t.nl...[color=blue]
            >I don't get it but <%= ... > should do??
            > I'm using it for resolving the script url.
            >
            >
            > "Nathan Sokalski" <njsokalski@hot mail.com> schreef in bericht
            > news:OBpEhuucGH A.5048@TK2MSFTN GP03.phx.gbl...[color=green]
            >>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
            >>RegisterClien tScriptBlock method that can be used. Any ideas or
            >>suggestions ? Thanks.
            >> --
            >> Nathan Sokalski
            >> njsokalski@hotm ail.com
            >> http://www.nathansokalski.com/
            >>[/color]
            >
            >[/color]


            Comment

            • Martijn Saly

              #7
              Re: Dynamically adding a stylesheet

              Flinky Wisty Pomm wrote:[color=blue]
              > 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("pa th/to/file", ResourceType.Cs s) 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.
              >[/color]

              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

              Comment

              • MSDN

                #8
                Re: Dynamically adding a stylesheet

                Flinky Wisty Pomm,

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

                Thank you,

                Sa


                "Flinky Wisty Pomm" <Pathogenix@gma il.com> wrote in message
                news:1147161222 .017984.44680@e 56g2000cwe.goog legroups.com...[color=blue]
                >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("pa th/to/file", ResourceType.Cs s) 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.
                >[/color]


                Comment

                • Kris

                  #9
                  Re: Dynamically adding a stylesheet

                  K.Scott Allen provided a useful trick for doing that.

                  The ContentPlaceHol der ¨C Not Just For Content

                  Comment

                  Working...