Change *.css on the fly at the server???

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

    Change *.css on the fly at the server???

    Seems to me that I should be able to do something like:

    ....runat="serv er" change from white.css to black.css...



    Of course if I could have found out how, I wouldn't be bothering you.

    Is something like that possible, so that I can let the users select the
    color scheme they like?

    Then after post back the new scheme would be effective.


    Thanks


  • Mark Rae [MVP]

    #2
    Re: Change *.css on the fly at the server???

    "_Who" <CalWhoNOSPAN@r oadrunner.comwr ote in message
    news:eqdhP8sBJH A.3392@TK2MSFTN GP03.phx.gbl...
    Of course if I could have found out how, I wouldn't be bothering you.
    >
    Is something like that possible, so that I can let the users select the
    color scheme they like?
    1) Provide a list of stylesheets for the user to choose, maybe in a
    DropDownList

    2) Store the path to the chosen stylesheet in a session variable

    3) Add the chosen stylesheet dynamically to the header of each page

    HtmlLink objCSS = new HtmlLink();
    objCSS.Attribut es.Add("href", Session["Stylesheet "].ToString());
    objCSS.Attribut es.Add("rel", "stylesheet ");
    objCSS.Attribut es.Add("type", "text/css");
    Header.Controls .Add(objCSS);

    To avoid having to do this on each page, either create a base page template
    and make all other pages inherit from it, or use a MasterPage / content
    pages architecture.


    --
    Mark Rae
    ASP.NET MVP


    Comment

    • _Who

      #3
      Re: Change *.css on the fly at the server???

      I copied your code to a master vb file, changed the first line to a Dim
      statement and to test I hard coded a style sheet path and it worked great.

      I need to add a DropDownList or menu item now.


      Would it make sense to drop a cookie in whatever the closing session event
      is and read it in the session startup.

      I don't know how complicated that is but unless you recommend against that,
      I'll read up on such things.


      Thanks




      "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
      news:e7dfIJtBJH A.4700@TK2MSFTN GP03.phx.gbl...
      "_Who" <CalWhoNOSPAN@r oadrunner.comwr ote in message
      news:eqdhP8sBJH A.3392@TK2MSFTN GP03.phx.gbl...
      >
      >Of course if I could have found out how, I wouldn't be bothering you.
      >>
      >Is something like that possible, so that I can let the users select the
      >color scheme they like?
      >
      1) Provide a list of stylesheets for the user to choose, maybe in a
      DropDownList
      >
      2) Store the path to the chosen stylesheet in a session variable
      >
      3) Add the chosen stylesheet dynamically to the header of each page
      >
      HtmlLink objCSS = new HtmlLink();
      objCSS.Attribut es.Add("href", Session["Stylesheet "].ToString());
      objCSS.Attribut es.Add("rel", "stylesheet ");
      objCSS.Attribut es.Add("type", "text/css");
      Header.Controls .Add(objCSS);
      >
      To avoid having to do this on each page, either create a base page
      template and make all other pages inherit from it, or use a MasterPage /
      content pages architecture.
      >
      >
      --
      Mark Rae
      ASP.NET MVP
      http://www.markrae.net

      Comment

      • _Who

        #4
        Re: Change *.css on the fly at the server???


        "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
        news:e7dfIJtBJH A.4700@TK2MSFTN GP03.phx.gbl...
        "_Who" <CalWhoNOSPAN@r oadrunner.comwr ote in message
        news:eqdhP8sBJH A.3392@TK2MSFTN GP03.phx.gbl...
        >
        >Of course if I could have found out how, I wouldn't be bothering you.
        >>
        >Is something like that possible, so that I can let the users select the
        >color scheme they like?
        >
        1) Provide a list of stylesheets for the user to choose, maybe in a
        DropDownList
        Thought I'd use a menu. Changed the web.sitemap and realized I don't even
        know how to look up: "how to specify the url for the siteMapNode to execute
        somthing on the page showing".

        All the instructions I found expects that the url will point to a new page.

        The SiteMapNode Class doesn't appear to have any properties nor events that
        allow that.

        The menu is in the master so it shows in all the pages.

        Need to specify for the url: do not change pages but go to someplace in this
        page (code actually from the master) and set a session variable.

        And force a post back?

        If the user clicked a menu item to change the colors I don't think he'd like
        the page to change.

        Is what I'm planning possible.

        Thanks for the other help
        >
        2) Store the path to the chosen stylesheet in a session variable
        >
        3) Add the chosen stylesheet dynamically to the header of each page
        >
        HtmlLink objCSS = new HtmlLink();
        objCSS.Attribut es.Add("href", Session["Stylesheet "].ToString());
        objCSS.Attribut es.Add("rel", "stylesheet ");
        objCSS.Attribut es.Add("type", "text/css");
        Header.Controls .Add(objCSS);
        >
        To avoid having to do this on each page, either create a base page
        template and make all other pages inherit from it, or use a MasterPage /
        content pages architecture.
        >
        >
        --
        Mark Rae
        ASP.NET MVP
        http://www.markrae.net

        Comment

        • _Who

          #5
          Re: Change *.css on the fly at the server??? revised

          Revised ("that" changed to "what I need"
          "_Who" <CalWhoNOSPAN@r oadrunner.comwr ote in message
          news:%23hl9UaxB JHA.4932@TK2MSF TNGP03.phx.gbl. ..
          >
          "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
          news:e7dfIJtBJH A.4700@TK2MSFTN GP03.phx.gbl...
          >"_Who" <CalWhoNOSPAN@r oadrunner.comwr ote in message
          >news:eqdhP8sBJ HA.3392@TK2MSFT NGP03.phx.gbl.. .
          >>
          >>Of course if I could have found out how, I wouldn't be bothering you.
          >>>
          >>Is something like that possible, so that I can let the users select the
          >>color scheme they like?
          >>
          >1) Provide a list of stylesheets for the user to choose, maybe in a
          >DropDownList
          >
          Thought I'd use a menu. Changed the web.sitemap and realized I don't even
          know how to look up: "how to specify the url for the siteMapNode to
          execute somthing on the page showing".
          >
          All the instructions I found expects that the url will point to a new
          page.
          >
          The SiteMapNode Class doesn't appear to have any properties nor events
          that allow what I need.
          >
          The menu is in the master so it shows in all the pages.
          >
          Need to specify for the url: do not change pages but go to someplace in
          this page (code actually from the master) and set a session variable.
          >
          And force a post back?
          >
          If the user clicked a menu item to change the colors I don't think he'd
          like the page to change.
          >
          Is what I'm planning possible.
          >
          Thanks for the other help
          >>
          >2) Store the path to the chosen stylesheet in a session variable
          >>
          >3) Add the chosen stylesheet dynamically to the header of each page
          >>
          >HtmlLink objCSS = new HtmlLink();
          >objCSS.Attribu tes.Add("href", Session["Stylesheet "].ToString());
          >objCSS.Attribu tes.Add("rel", "stylesheet ");
          >objCSS.Attribu tes.Add("type", "text/css");
          >Header.Control s.Add(objCSS);
          >>
          >To avoid having to do this on each page, either create a base page
          >template and make all other pages inherit from it, or use a MasterPage /
          >content pages architecture.
          >>
          >>
          >--
          >Mark Rae
          >ASP.NET MVP
          >http://www.markrae.net
          >
          >

          Comment

          • Mark Rae [MVP]

            #6
            Re: Change *.css on the fly at the server???

            "_Who" <CalWhoNOSPAN@r oadrunner.comwr ote in message
            news:uB$MnGxBJH A.4884@TK2MSFTN GP02.phx.gbl...
            Would it make sense to drop a cookie in whatever the closing session event
            is and read it in the session startup.
            Depends if you need the stylesheet choice to be persisted across sessions.
            Don't forget that some users switch cookies off for (perceived) security
            reasons...
            I don't know how complicated that is



            --
            Mark Rae
            ASP.NET MVP


            Comment

            • Mark Rae [MVP]

              #7
              Re: Change *.css on the fly at the server???

              "_Who" <CalWhoNOSPAN@r oadrunner.comwr ote in message
              news:%23hl9UaxB JHA.4932@TK2MSF TNGP03.phx.gbl. ..
              Need to specify for the url: do not change pages but go to someplace in
              this page (code actually from the master) and set a session variable.
              >
              And force a post back?
              >
              If the user clicked a menu item to change the colors I don't think he'd
              like the page to change.
              >
              Is what I'm planning possible.

              Yes, but it will require a round-trip to the server because you can only set
              / retrieve session variables server-side...


              --
              Mark Rae
              ASP.NET MVP


              Comment

              • _Who

                #8
                Re: Change *.css on the fly at the server???

                I can't find out how to make a menu-click exercise master code with out
                changing the page.

                That is, if I add a page url to the menuitem and the item gets clicked user
                will see his page change.

                A url is the only thing I see on a menuitem to handle a click and that
                doesn't appear to be what I need.


                All I want to happen is store a new session variable value and run the code
                you showed me.

                If the menuitem had a click event to the master code behind I would have
                used that.

                Got any idea about how to do this


                Thanks for all the help



                "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
                news:%23ejdCP1B JHA.4932@TK2MSF TNGP03.phx.gbl. ..
                "_Who" <CalWhoNOSPAN@r oadrunner.comwr ote in message
                news:%23hl9UaxB JHA.4932@TK2MSF TNGP03.phx.gbl. ..
                >
                >Need to specify for the url: do not change pages but go to someplace in
                >this page (code actually from the master) and set a session variable.
                >>
                >And force a post back?
                >>
                >If the user clicked a menu item to change the colors I don't think he'd
                >like the page to change.
                >>
                >Is what I'm planning possible.
                >
                >
                Yes, but it will require a round-trip to the server because you can only
                set / retrieve session variables server-side...
                >
                >
                --
                Mark Rae
                ASP.NET MVP
                http://www.markrae.net

                Comment

                • Mark Rae [MVP]

                  #9
                  Re: Change *.css on the fly at the server???

                  "_Who" <CalWhoNOSPAN@r oadrunner.comwr ote in message
                  news:uMn76s3BJH A.1892@TK2MSFTN GP04.phx.gbl...
                  If the menuitem had a click event to the master code behind I would have
                  used that.
                  Set the NavigateUrl property to an empty string.


                  Use the Value property
                  Gets or sets a non-displayed value used to store any additional data about the menu item, such as data used for handling postback events.



                  --
                  Mark Rae
                  ASP.NET MVP


                  Comment

                  • _Who

                    #10
                    Re: Change *.css on the fly at the server???

                    I'm using much of your time and because I don't know how to ask the right
                    question I'm not advancing.

                    Maybe if I tell you what I've done.

                    I create the menu using web.sitemap containing a sitemap, and in my master
                    file

                    <asp:Menu runat="server" ID="MainMenu" Style="Font-Size:16pt; border-style:
                    ridge; border-color: Maroon;

                    border-width: 4px" StaticDisplayLe vels="2" DataSourceID="S iteMapDataSourc e1"



                    web.site contains these (along with other items):

                    <siteMapNode title="Options" url="d.aspx">

                    <siteMapNode title="Black Background" url="a.aspx" />

                    <siteMapNode title="White Background" url="b.aspx" />

                    <siteMapNode title="Textured Background" url="c.aspx" />

                    </siteMapNode>



                    I know about :
                    Protected Sub MainMenu_MenuIt emClick(ByVal sender As Object, ByVal e As
                    MenuEventArgs)

                    and that MenuEventArgs has a text property that I can use to identify which
                    item was clicked.

                    But I can't get past the requirement that each siteMapNode have a nonblank
                    url.

                    What I need to be able todo when the user clickes and item is to have the
                    page be unchanged, and have the click event raised or have some routine on
                    the master run.

                    Like if I could use for the url *.subroutine1
                    meaning go to subroutine1 on this page.


                    got any ideas?


                    THANKS





                    "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
                    news:OaitUP4BJH A.3496@TK2MSFTN GP03.phx.gbl...
                    "_Who" <CalWhoNOSPAN@r oadrunner.comwr ote in message
                    news:uMn76s3BJH A.1892@TK2MSFTN GP04.phx.gbl...
                    >
                    >If the menuitem had a click event to the master code behind I would have
                    >used that.
                    >
                    Set the NavigateUrl property to an empty string.

                    >
                    Use the Value property
                    Gets or sets a non-displayed value used to store any additional data about the menu item, such as data used for handling postback events.

                    >
                    >
                    --
                    Mark Rae
                    ASP.NET MVP
                    http://www.markrae.net

                    Comment

                    • _Who

                      #11
                      Re: Change *.css on the fly at the server???


                      "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
                      news:OaitUP4BJH A.3496@TK2MSFTN GP03.phx.gbl...
                      "_Who" <CalWhoNOSPAN@r oadrunner.comwr ote in message
                      news:uMn76s3BJH A.1892@TK2MSFTN GP04.phx.gbl...
                      >
                      >If the menuitem had a click event to the master code behind I would have
                      >used that.
                      Somehow I kept missing the MenuItemClick event.
                      Don't know how but I did.

                      Thanks

                      >
                      Set the NavigateUrl property to an empty string.

                      >
                      Use the Value property
                      Gets or sets a non-displayed value used to store any additional data about the menu item, such as data used for handling postback events.

                      >
                      >
                      --
                      Mark Rae
                      ASP.NET MVP
                      http://www.markrae.net

                      Comment

                      Working...