There are many ways to change skins. The simplest is usually to switch page CSS, and CSS is usually written in an external CSS file. Then switching css is actually changing the link href path in html. I searched online. There are generally two ways:
1. Put a holder control on the page. Then write the current user's style css link to the page programmatically.
2. Set css styles on each control through the reflection mechanism.
The above two methods are quite troublesome.
The first requires placing a holder control on each page. A similar approach is to add runat=server to the link tag. If there are too many pages, it will be more troublesome.
There is no need to consider the second one. There are many problems with performance programming efficiency.
I remember that when I was learning DNN, I found a way to modify the default action address in the form. Please refer to it directly. not bad:
Directly override the Render event
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
StringWriter sw = new StringWriter();
HtmlTextWriter htmlWriter = new HtmlTextWriter(sw);
base.Render(htmlWriter);
//The style css selected by the current user
string css = "<link href="css url" rel="stylesheet" type="text/css">" ;
string html = sw.ToString() ;
int startPoint = html.IndexOf("</head>", StringComparison.CurrentCultureIgnoreCase);
if (startPoint > 0)
{
html = html.Insert(startPoint, css);
}
writer.Write(html);
}
Put this in the base class PageBase of each page. That would be much more convenient.
Of course, if you don't want every page to inherit a custom base class, you can also write it in HttpModule. It's also very convenient.
Write it in one place, and it will be useful for every page.
http://www.cnblogs.com/kwklover/archive/2007/01/03/610822.html