Asp.net|css
Multi-interface by enabling pages to dynamically load different CSS
Method One:
<% @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"]= "portal.css";
This control does not produce any visible output, only as a container for other controls, where you can add, insert, or remove controls.
MYCSS.CONTROLS.ADD (Objlink);
}
</script>
<title>c#</title>
<asp:placeholder id= "mycss" runat= "Server" ></asp:placeholder>
<body bgcolor= "#ffcc66" style= "font:9pt" >
<form runat= "Server" >
</form>
</body>
Change the interface by dynamically setting the style of all the same controls on the page:
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. The style of the text box is found to be uniformly modified to "textbox_show"