How to Implement the Web control text box Reset function, web control text box reset

Source: Internet
Author: User

How to Implement the Web control text box Reset function, web control text box reset

A program has been developed in ASP. NET. After data is inserted, the TextBox control needs to be Reset. If there are only one or two file boxes, there may be no problem. If there are many text boxes on the webpage, you will have a problem.
In addition, some text boxes have default values, which cannot be implemented through loops.

For example, I saw a netizen writing on the forum today:

protected void Button2_Click(object sender, EventArgs e)    {        this.TextBox1.Text = this.TextBox3.Text = this.TextBox4.Text = this.TextBox5.Text = this.TextBox7.Text = this.TextBox8.Text = this.TextBox9.Text = this.TextBox10.Text = "";    }


Considering that you may Reset other Web controls such as CheckBox and DropDownList, you can write an interface:



The preceding Reset is a TextBox Control, so you can write a class that inherits TextBox and then implement the Reset method of the interface:

 
For example, there are many text boxes under the webpage, some of which have default values and some do not. The user first enters some values, or changes the default value, then click the Reset button:

<Form id = "form1" runat = "server"> <div> <asp: TextBox ID = "TextBox1" runat = "server" Text = "Leo"> </asp: textBox> <br/> <asp: TextBox ID = "TextBox2" runat = "server"> </asp: TextBox> <br/> <asp: textBox ID = "TextBox3" runat = "server"> </asp: TextBox> <br/> <asp: textBox ID = "TextBox4" runat = "server" Text = "Yang"> </asp: TextBox> <br/> <asp: textBox ID = "TextBox5" runat = "server"> </asp: TextBox> <br/> <asp: textBox ID = "TextBox6" runat = "server"> </asp: TextBox> <br/> <asp: textBox ID = "TextBox7" runat = "server" Text = "Insus. NET "> </asp: TextBox> <br/> <asp: TextBox ID =" TextBox8 "runat =" server "> </asp: textBox> <br/> <asp: Button ID = "Button1" runat = "server" Text = "Reset" OnClick = "button#click"/> </div> </form>View Code





The following is the Button1_Click event of the Reset button:

 
Dynamic Real-time operations:



Controls such as DropDownList and CheckBox can be implemented after time ......

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.