Recently visited the construction site https://ibsbjstar.ccb.com.cn/V5/index.html#, (in fact, in oblog, http://www.oblog.cn also adopted similar techniques, but the method is different)
It can be found that different colors can appear in different text boxes. It is very easy to complete this function, but if there are many similar functions, it is obviously tiring to set control styles one by one, A simple processing method is used to write a method for the system to execute it. See the following code:
Class basepage: Page
{
Public static void setinputcontrolshighlight (control container, string classname, bool onlytextboxes)
{
Foreach (control CTL in container. Controls)
{
If (onlytextboxes & CTL is textbox) | CTL is textbox | CTL is dropdownlist |
CTL is ListBox | CTL is checkbox | CTL is radiobutton |
CTL is radiobuttonlist | CTL is checkboxlist)
{
Webcontrol wctl = CTL as webcontrol;
Wctl. Attributes. Add ("onfocus", String. Format ("This. classname = '{0}';", classname ));
Wctl. Attributes. Add ("onblur", "This. classname = '';");
}
Else
{
If (CTL. Controls. Count> 0)
Setinputcontrolshighlight (CTL, classname, onlytextboxes );
}
}
}
}
Define a class: override onfocus and onblur. When you select different controls, different styles will appear. You need to define the style name.
Note: This basepage is derived from the page class. Therefore, it should be:
Webform1: mypage
{
// Call the setinputcontrolshighlight Method
}
In this way,
Http://www.cnblogs.com/mqingqing123/archive/2007/02/28/658922.html