Click here to Skip to main content
15,915,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a TextBox with Required Field Validator and having two buttons
1.Save
2.Close


When i click on save button it is validating the TextBox Empty or Not which is my Requirement.
But When i click on Close button also it is validating the TextBox which is not my Requirement.

How to disable validation for Close Button.
Posted
Updated 14-Jul-20 19:18pm

You need to set this property for your Close button
ASP.NET
<asp:button id="btnCancel" runat="server" text="Cancel" causesvalidation="false" />
 
Share this answer
 
v2
C#
<asp:textbox id="txtNewName" runat="server" xmlns:asp="#unknown" />
 <asp:requiredfieldvalidator id="vldtxtNewName" runat="server" controltovalidate="txtNewName" xmlns:asp="#unknown"> ValidationGroup="NewDepartmentValidationGroup"
 ErrorMessage="Required Field" />


<asp:button id="save" runat="server" text="Create"
      ValidationGroup="NewDepartmentValidationGroup" OnClick="cmdCreate_Click" causesvalidation="true" /></asp:button>

<asp:button id="close" runat="server" text="Create"
       OnClick="cmdCreate_Click" /></asp:button></asp:requiredfieldvalidator>



set the validation group property for save button
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900