ASP. NET tips-use styles

Source: Internet
Author: User

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

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.