Click here to Skip to main content
15,127,066 members
Please Sign up or sign in to vote.
0.00/5 (No votes)

i have some textboxs in my page and some validation controls . i want to fire the validations controls in btn click "btn name : Save" . my page have three btn , how to fire validation in save btn only , not in any btn .

You have two options :
1 - use ValidationGroup property : all the controls and the save button have the same value for the ValidationGroup property and do not assign value for ValidationGroup property for other buttons
2 - set CausesValidation to false for the buttons , which you do not want them to fire the validation script
Darsh_Basha 31-Mar-13 11:30am
@Omar Adnan Isaid

can u explain how to do this "CausesValidation" in my buttons in my page
my page inhabited from master page. the master page contains three buttons
Omar Isaid 1-Apr-13 1:53am
R-Click on the button - that you do not want to fire the validation - choose properties from the appeared context menu and change the property CausesValidation from true to false.And so , the validation will not fire any more when you click this button
minu1989 1-Apr-13 2:16am
<asp:TextBox ID="TxtDisplayName" runat="server" Width="490px">

<asp:RequiredFieldValidator SetFocusOnError="True" ControlToValidate="TxtDisplayName"
Display="Dynamic" ValidationGroup="MailSetting" ID="RequiredFieldValidator4"
runat="server" ErrorMessage="">


<asp:Button ID="btnExtUserCreate" runat="server" ValidationGroup="MailSetting" OnClick="btnExtUserCreate_Click" />

use this code-->
Set validationGroup="Validation" to all validation control and save button, it will validate your control only when you click on save button.....
Always check page validation on Button Click.

HTML Code:

            <asp:textbox id="TxtDisplayName" runat="server" width="490px" xmlns:asp="#unknown">

 <asp:requiredfieldvalidator setfocusonerror="True" controltovalidate="TxtDisplayName" xmlns:asp="#unknown">
                Display="Dynamic" ValidationGroup="MailSetting" ID="RequiredFieldValidator4"
                runat="server" ErrorMessage="">

   <asp:button id="btnExtUserCreate" runat="server" validationgroup="MailSetting" onclick="btnExtUserCreate_Click" xmlns:asp="#unknown" />

CS Code

protected void btnExtUserCreate_Click(object sender, EventArgs e)
// your logic

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