ASP. NET learning-how does CSS implement multi-interface implementation? The principle is to implement multiple interfaces by dynamically loading different CSS pages.
How to implement multiple interfaces with CSS in ASP. NET:
- <%@ Page language ="C #"%>
- <%@ ImportNamespace="System. Data"%>
- <Script language ="C #"Runat ="Server">
- Public VoidPage_load (Object obj, EventArgs e)
- {
- // Create a server control.
- // The specified tag "LINK" initializes a new instance of this type.
- HtmlGenericControl objLink =NewHtmlGenericControl ("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. It is only used as a container for other controls. You can add, insert, or remove controls in it.
- MyCSS. Controls. Add (objLink );
- }
- </Script>
- <Html>
- <Head>
- <Title> c # </title>
- <Asp: placeholder id ="MyCSS"Runat ="Server"></ Asp: placeholder>
- </Head>
- <Body bgColor ="# Ffcc66"Style ="FONT: 9pt">
- <Form runat ="Server">
-
- </Form>
- </Body>
- </Html>
You can change the interface by dynamically setting the styles of all controls of the same type on the page:
ASP. NET learning CSS implementation multi-interface method 2:
You can modify the CssClass attribute of a WEB Control to conveniently set and modify the style of the control. However, in actual development, setting the CssClass attribute of controls one by one is very cumbersome, so this idea is not widely used. however, the following code snippet demonstrates how to change the style of all controls of the same type on the page at one time to implement simple functions such as SKIN.
The Code is as follows:
- Public VoidPage_load (Object obj, EventArgs e)
- {
- If(! Page. IsPostBack ){
- // Set the style for all controls on the page.
- SetCSS (Page. Controls );
- }
- }
-
- Private VoidSetCSS (System. Web. UI. ControlCollection vControls)
- {
- For(IntI = 0; I <vControls. Count; I ++)
- {
- System. Web. UI. Control vControl = vControls [I];
-
- // Obtain the control type
- // You 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 VoidTextBox_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 changed to "TextBox_show ".
I will introduce you to the CSS Implementation of ASP. NET and try it out.
- ASP. NET program keeps two decimal points for parsing
- Examples of ASP. NET File Upload controls
- Nine steps for learning ASP. NET
- Advantages of ASP. NET compared with ASP
- Analysis of ASP. NET MD5 and SHA1 encryption methods