ASP. NET Switch CSS implementation of multi-style pages (Collection)

Source: Internet
Author: User
ASP. net Switch CSS implementation of multi-style PAGE method 1 <% @ page Language = "C #" %> <% @ import namespace = "system. data "%> <script language =" C # "runat =" server "> Public void page_load (Object OBJ, eventargs e) {// create a server control. // The specified tag "Link" initializes a new instance of this type. 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 generate 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>  Code Section demonstrates how to change the style of all controls of the same type on the page at one time, and implement simple functions such as skin. The Code is as follows: Reference segment: Public void page_load (Object OBJ, eventargs e) {If (! Page. ispostback) {// set 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]; // obtain the control type. // you can increase the control type and the corresponding processing method. 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>
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.