ASP. NET learning-CSS implementation multi-interface two methods

Source: Internet
Author: User
Tags sha1 encryption

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:

 
 
  1. <%@ Page language ="C #"%>
  2. <%@ ImportNamespace="System. Data"%>
  3. <Script language ="C #"Runat ="Server">
  4. Public VoidPage_load (Object obj, EventArgs e)
  5. {
  6. // Create a server control. 
  7. // The specified tag "LINK" initializes a new instance of this type. 
  8. HtmlGenericControl objLink =NewHtmlGenericControl ("LINK");
  9. ObjLink. ID = ID;
  10. ObjLink. Attributes ["Rel"] ="Stylesheet";
  11. ObjLink. Attributes ["Type"] ="Text/css";
  12. ObjLink. Attributes ["Href"] ="Portal.css";
  13.  
  14. // 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. 
  15. MyCSS. Controls. Add (objLink );
  16. }
  17. </Script>
  18. <Html>
  19. <Head>
  20. <Title> c # </title>
  21. <Asp: placeholder id ="MyCSS"Runat ="Server"></ Asp: placeholder>
  22. </Head>
  23. <Body bgColor ="# Ffcc66"Style ="FONT: 9pt">
  24. <Form runat ="Server">
  25.  
  26. </Form>
  27. </Body>
  28. </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:

 
 
  1. Public VoidPage_load (Object obj, EventArgs e)
  2. {
  3. If(! Page. IsPostBack ){
  4. // Set the style for all controls on the page. 
  5. SetCSS (Page. Controls );
  6. }
  7. }
  8.  
  9. Private VoidSetCSS (System. Web. UI. ControlCollection vControls)
  10. {
  11. For(IntI = 0; I <vControls. Count; I ++)
  12. {
  13. System. Web. UI. Control vControl = vControls [I];
  14.  
  15. // Obtain the control type 
  16. // You can add control types and corresponding processing methods. 
  17. String PType = vControl. GetType (). Name;
  18. Switch(PType)
  19. {
  20. Case "TextBox":
  21. TextBox_CSS (TextBox) vControl );
  22. Break;
  23. Case "Button":
  24. // Button_CSS (Button) vControl ); 
  25. Break;
  26. Case "DataGrid":
  27. // DataGrid_CSS (DataGrid) vControl ); 
  28. Break;
  29. }
  30. If(VControl. Controls. Count> 0)
  31. SetCSS (vControl. Controls );
  32. }
  33. }
  34.  
  35.  
  36. Private VoidTextBox_CSS (TextBox tb ){
  37. Tb. CssClass ="TextBox_show";
  38. }
  39.  
  40. <Form runat ="Server">
  41. <Asp: textbox id ="Search1"Runat ="Server"/>
  42. <Asp: textbox id ="Search2"CssClass ="INPUT"Runat ="Server"/>
  43. </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.

  1. ASP. NET program keeps two decimal points for parsing
  2. Examples of ASP. NET File Upload controls
  3. Nine steps for learning ASP. NET
  4. Advantages of ASP. NET compared with ASP
  5. Analysis of ASP. NET MD5 and SHA1 encryption methods

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.