How I can Change Css Style Sheet at runtime?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: How I can Change Css Style Sheet at runtime?

Hybrid View

  1. #1
    Geeta Guest

    How I can Change Css Style Sheet at runtime?


    I have different css style sheets.Each of which has different color
    scheme for the web site.I have used the <Link rel="stylesheet" type="text/css"
    href="css/stylesheet.css"> tag to apply the css style sheet.
    I want to allow the user to choose from those different color schemes
    and apply that color scheme to entire web site.I am using ASP.Net & C# Language.So
    How I change the css style sheet at runtime. Basically, I want to change
    the href attribute of <Link> tag. Is there any way to apply style sheet that
    user selects?


    Thank you,
    Geeta



  2. #2
    James World Guest

    Re: How I can Change Css Style Sheet at runtime?


    This isn't a C# question... but I'll answer it anyway.

    I can't think of a clean and straightforward way to do this client-side,
    but server-side it is pretty easy.

    Assuming you have a page containing a form which allows the user to choose
    between the stylesheets, you can then keep the name of the current stylesheet
    in a session variable and write it into the Link tag on each page.

    If you can't include server-side code in your pages, the least painful client
    side options I can think of are (1) have multiple copies of the pages (use
    a custom app to generate them though!), or (2) use javascript functions to
    set the different styles up.

    HTH

    James.

    "Geeta" <giit@usa.net> wrote:
    >
    > I have different css style sheets.Each of which has different color
    >scheme for the web site.I have used the <Link rel="stylesheet" type="text/css"
    >href="css/stylesheet.css"> tag to apply the css style sheet.
    > I want to allow the user to choose from those different color schemes
    >and apply that color scheme to entire web site.I am using ASP.Net & C# Language.So
    >How I change the css style sheet at runtime. Basically, I want to change
    >the href attribute of <Link> tag. Is there any way to apply style sheet

    that
    >user selects?
    >
    >
    >Thank you,
    >Geeta
    >
    >



  3. #3
    Join Date
    Mar 2010
    Posts
    1
    <%@ Page Language="C#"%>
    <script runat="server">

    protected void Page_Init(object sender, EventArgs e)
    {
    // Define an HtmlLink control.
    HtmlLink myHtmlLink = new HtmlLink();
    myHtmlLink.Href = "~/StyleSheet.css";
    myHtmlLink.Attributes.Add("rel", "stylesheet");
    myHtmlLink.Attributes.Add("type", "text/css");

    // Add the HtmlLink to the Head section of the page.
    Page.Header.Controls.Add(myHtmlLink);

    }
    </script>
    <script>

    </script>
    <html>
    <head id="head1"
    runat="server">
    <title>HtmlLink Example Page</title>
    </head>
    <body>
    <form id="form1"
    runat="server">
    <h1>HtmlLink Example Page</h1>
    This is some text in the body of the Web Forms page.
    </form>
    </body>
    </html>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center