0

I am doing a customer registration form which allows new customers to fill in. I've put requirefieldvalidator every field and comparevalidator for comparingt the password and confirmpassword. I have submit button and back button. The problem i encountered is no matter what button i clicked, submit button or back button, if i don't fill in any of the requirement i will not proceed. This is fine to the submit button as it needs to check whether every detail is filled in, but for back button, i want to allow customers to go back to previous page by clicking this button which validators are not needed.

Is there any way to control the validators?

1

1 Answer 1

1

use ValidationGroup in all validation with same group name and give same group name for button also

Exapmle

<asp:TextBox runat="server" ID="tb1"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ID="rfv1" ControlToValidate="tb1" ErrorMessage="*" ValidationGroup="gvSave">
</asp:RequiredFieldValidator>

<asp:TextBox runat="server" ID="tb2" Visible="false"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ID="rfv2" ControlToValidate="tb2" ErrorMessage="*" Enabled="false" ValidationGroup="gvSave">
</asp:RequiredFieldValidator>

<asp:Button runat="server" ID="btn1" Text="Save" onclick="btn1_Click" ValidationGroup="gvSave"/>
<asp:Button runat="server" ID="btn2" Text="Show" onclick="btn2_Click" />

Here

when you click btn1 it check for validation and

for button btn2 will not check for validation

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.