Asp.net|css
Look at the old cat's article, by making the page dynamically loaded with different CSS to achieve personalized interface (such as personalized blog interface) have the following several methods
Method One:
HtmlGenericControl defines methods, properties, and events for all HTML server control elements that are not represented by a specific. NET Framework class.
<link href= "Login.css" type= "Text/css" rel= "stylesheet" >
Where the href attribute can be dynamically obtained from the user Configuration and then page Setup.
<% @page language= "C #"%>
<% @import namespace= "System.Data"%>
<script language= "C #" runat= "Server" >
public void Page_Load (Object Obj,eventargs E)
{
Create a server-side control.
The specified tag "LINK" Initializes a new instance of this class.
HtmlGenericControl objlink=new HtmlGenericControl ("LINK");
Objlink.id=id;
objlink.attributes["rel"]= "stylesheet";
objlink.attributes["type"]= "Text/css";
objlink.attributes["href"]= "login.css";
Mycss as placeholder container control, placed in
MYCSS.CONTROLS.ADD (Objlink);
}
</script>
<title>c#</title>
<asp:placeholder id= "mycss" runat= "Server" ></asp:placeholder>
<body >
<form runat= "Server" >
</form>
</body>
Method Two:
You can easily set and modify the style of a control by changing the CssClass property of the Web control.
However, in the actual development process, set the control of the CssClass property, very cumbersome, so this idea is not widely used.
But the following code snippet shows a way to change the style of all the same controls on a page at once, with simple skin features.
The code is as follows:
public void Page_Load (Object Obj,eventargs E)
{
if (! Page.IsPostBack) {
Sets the style for all controls on the page.
Setcss (Page.controls);
}
}
private void Setcss (System.Web.UI.ControlCollection vcontrols)
{
for (int i=0;i<vcontrols.count;i++)
{
System.Web.UI.Control Vcontrol=vcontrols[i];
Get the type of the control
Can add control types and corresponding processing methods
String Ptype=vcontrol.gettype (). Name;
Switch (ptype)
{
Case "TextBox":
Textbox_css ((TextBox) vcontrol);
Break
Case "button":
Button_css ((Button) vcontrol);
Break
Case "DataGrid":
Datagrid_css ((DataGrid) vcontrol);
Break
}
if (vcontrol.controls.count>0)
Setcss (Vcontrol.controls);
}
}
private void Textbox_css (TextBox TB) {
Tb. Cssclass= "Textbox_show";
}
<form runat= "Server" >
<asp:textbox id= "Search1" runat= "Server"/>
<asp:textbox id= "Search2" cssclass= "INPUT" runat= "Server"/>
</form>
After running, view the page source code. You can find that the style of the text box has been uniformly modified to "textbox_show".