Sarah Collins Sarah Collins - 14 days ago 9
C# Question

Reset button c# asp.net and clear validation controls

I have a c# asp.net registration form , but i'm unable to use the reset button to achieve the objective I want. Upon clicking the reset button, the validators I have demand that I fill up ALL textboxes before I can reset the fields.

If a user were to fill up half of the form and use the reset fields, the reset button does not achieve the objective I want it to, as all textboxes have to be filled.

The codes I'm using are as follows:

protected void resetButton_Click(object sender, EventArgs e)
{Response.Redirect(Registration.aspx);}

Answer

Since this looks like Asp.Net Web Forms, as opposed to MVC, On the aspx file where you set up the button, set the CausesValidation property to false. Link: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.causesvalidation(v=vs.110).aspx

Example:

<asp:Button CausesValidation="False" />