Web Control text box Reset function, web control reset
In the previous article "how to implement Web control text box Reset function" http://www.cnblogs.com/insus/p/4120889.html Insus. NET only implements the text box function. One or more, with default values and no values. As long as you Click Reset, We need to Reset the Web control.
By referring to the blog post, you can write Reset Functions for other controls. Such as DropDownLsit, ListBox, CheckBox, CheckBoxList, and RadioButtonList.
To implement the Reset function of any control, you must create a custom class and inherit it.
The following is the CheckBox control:
Reset function of ListBox control:
CheckBoxList control:
DropDownList control:
RadioButtonList control:
The following shows how to use a program:
<Asp: TextBox ID = "TextBox1" runat = "server" Text = "Leo"> </asp: TextBox> <br/> <asp: dropDownList ID = "DropDownList1" runat = "server"> <asp: ListItem Value = "A" Text = "A"> </asp: ListItem> <asp: listItem Value = "B" Text = "B"> </asp: ListItem> <asp: ListItem Value = "C" Text = "C"> </asp: listItem> <asp: ListItem Value = "D" Text = "D"> </asp: ListItem> <asp: listItem Value = "E" Text = "E"> </asp: ListItem> <asp: ListItem Value = "F" Text = "F"> </asp: listItem> <asp: ListItem Value = "G" Text = "G"> </asp: ListItem> </asp: DropDownList> <br/> <asp: checkBox ID = "CheckBox1" runat = "server"/> <br/> <asp: CheckBoxList ID = "CheckBoxList1" runat = "server" RepeatColumns = "7"> <asp: listItem Value = "A" Text = "A"> </asp: ListItem> <asp: ListItem Value = "B" Text = "B"> </asp: listItem> <asp: ListItem Value = "C" Text = "C"> </asp: ListItem> <asp: listItem Value = "D" Text = "D"> </asp: ListItem> <asp: ListItem Value = "E" Text = "E"> </asp: listItem> <asp: ListItem Value = "F" Text = "F"> </asp: ListItem> <asp: listItem Value = "G" Text = "G"> </asp: ListItem> </asp: CheckBoxList> <br/> <asp: radioButtonList ID = "RadioButtonList1" runat = "server" RepeatColumns = "3"> <asp: ListItem Value = "A" Text = "A"> </asp: listItem> <asp: ListItem Value = "B" Text = "B"> </asp: ListItem> <asp: listItem Value = "C" Text = "C"> </asp: ListItem> </asp: RadioButtonList> <br/> <asp: listBox ID = "ListBox1" runat = "server" SelectionMode = "Multiple"> <asp: ListItem Value = "A" Text = "A"> </asp: listItem> <asp: ListItem Value = "B" Text = "B"> </asp: ListItem> <asp: listItem Value = "C" Text = "C"> </asp: ListItem> <asp: ListItem Value = "D" Text = "D"> </asp: listItem> <asp: ListItem Value = "E" Text = "E"> </asp: ListItem> </asp: ListBox> <br/> <asp: button ID = "Button1" runat = "server" Text = "Reset" OnClick = "button#click"/>View Code
Currently, writing the Reset button event cannot copy the method in the previous article, but you need to modify it because all the custom interfaces have been implemented as IResetControlable.
Dynamic Operation Demo:
In the demonstration of all the controls above, only one is listed. If there is a single button event, how do we optimize the above program and what needs to be modified and what does not need to be changed. In fact, in asp.net development, using controls gives more opportunities to learn object-oriented technologies and knowledge.
The following content is added:
Because controls such as ListBox, CheckBoxList, DropDownList, and RadioButtonList inherit the ListControl class, they can be classified as an Adapter class:
Write a new ListControlReset class:
In this way, you can delete the following Adapter classes:
Finally, the program can be restructured:
In this way, you do not need to write your own independent Adapter class.