Dynamically change the page style with C # code

xiaoxiao2021-03-06  39

During the development of Web system, the CSS enhancement and beautification page style has become a standard 'process'. Develop BS systems in the Visual Studio .NET environment, you can easily set and modify the style of the control by setting the CSSClass property of the web control.

However, in the actual development process, let developers set the CSSClass attribute of the control one by one, not only cumbersome, but also easily errors, more headaches, may also cause trouble on maintenance.

The following code segment demonstrates a solution to achieving good results in practical applications, hoping to play the effect of bricking jade. Based on this idea, I believe that everyone can develop more applications, such as achieving simple SKIN features.

code show as below. The method of use is to call loadPageCSS () in each .ASPX page_load () method.

Public void loadingPagecss (system.web.ui.page vpage) {if (! vpage.ispostback) {setControlscss (vpage.controls);}}

Private void setControlscss (System.Web.ui.ControlColColLeth vcontrols) {for (int i = 0; i

{

System.web.ui.control vcontrol = vControls [i];

String vControlName = vcontrol.gettype (). name;

Switch (vcontrolname)

{

Case "TextBox":

Textbox_css ((TextBox) vcontrol);

Break;

Case "RadiobuttonList":

RadiobuttonList_CSS ((RadiobuttonList) vcontrol;

Break;

Case "DropDownList":

DROPDOWNLIST_CSS ((DropDownList) vcontrol;

Break;

Case "Button":

Button_CSS ((Button) vcontrol;

Break;

Case "DataGrid":

DataGrid_css ((DataGrid) vcontrol;

Break;

///

More control types and processing methods /// .... /// ...} if (vcontrol.controls.count> 0) {setControlscss (vcontrol.controls);}}

}

Private void radiobuttonlist_css (radiobuttonlist vrdolist) {vrdolist.cssclass = "radiobuttonlist_show";

转载请注明原文地址:https://www.9cbs.com/read-116340.html

New Post(0)