Field validation of a single button only

Viewed 20036

I have the following validator on a textbox inside a modal dialog box.

<asp:RequiredFieldValidator runat = "server" 
                            ErrorMessage = "Role name can not be empty."
                            ControlToValidate = "tbxRoleName" />

It works like it should, except that the validation triggers on every other buttons OnClick handler on the aspx-page too. Since the dialog is invisible it looks like buttons just dont work on the page. My workaround is to add CausesValidation = "false" on all buttons on the page. But it is a very bad solution and I think there should be a smarter way.

4 Answers

Also you can use 'causesvalidation' to the button. If it is false Button will not response to Validation in aspx page.

Example: <asp:Button runat="server" Text="Cancel" CausesValidation="false" />

Related