Search code examples
asp.netvb.netresetrequiredfieldvalidatorrangevalidator

ASP.Net, VB: Clearing fields on the webpage


I am developing a website using ASP.Net and VB.

On one of the pages, there are certain fields (TextBoxes and a DropDownList). User is supposed to fill out those fields and click 'Submit' button. Also, there is a button 'Clear Values', which if clicked by user should clear the fields on the webpage.

The code I have written for clearing the fields was:

txtBox1.Text =  String.Empty

for all the TextBoxes. But, that didn't work, as I have used few validators like RequiredFieldValidator, RangeValidator, RegularExpressionValidator etc. to validate the fields. So, when the user fills out few fields and then clicks on 'Clear Values' button in order to clear all the fields, then the fields don't get cleared. Insted of that the validations work and the error messages appear as per those validations.

I also tried the following code to clear all the fields:

 Response.Redirect("UserData.aspx");

(where 'UserData.aspx' is name of that webpage only). But, still it gives the same validation error messages.

How to tackle this?


Solution

  • The button for "Clear Values"

    You have to set its property CausesValidation = "false"