-
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
-
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
>
>
-
<%@ 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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks