Click here to Skip to main content
12,349,363 members (67,074 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET
I have used requered field validators ,but I have two button on this page.validation will fire on both page.when I click button1 then validation will fire.I have to not fire validation when I click on second button.But validation also fire when i click on second button.what i have to do?
Posted 2-Jan-13 23:46pm
Edited 2-Jan-13 23:47pm
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

You can use ValidationGroup property. Assign same value for button1 and RequiredfieldValidator1 and different for other.

Let me know if you need any help.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Use CausesValidation="False" for second button
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 6

What I think is that you have two buttons on the page and you want to fire the validation only on 1st button. if you want to do only this much than for this you can set the CausesValidation property as false for 2nd button

Do it from the property window
or

<asp:button id="Button2" text="Validate" >
onclick="Button2_Click"
causesvalidation=false runat="Server" />
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Mkae Validation group for perticular one Button and other controls.
refer below example
<!DOCTYPE html>
<html>
<body>
   <form runat="server">
     <p>ValidationGroup 1</p>
     Name:<asp:textbox id="tbName" runat="Server" />
     <asp:requiredfieldvalidator id="ReqFieldVal1"
     controltovalidate="tbName"
     validationgroup="valGroup1"
     errormessage="Required" runat="Server" />
     <br>
     Age:<asp:textbox id="tbAge" runat="Server" />
     <asp:requiredfieldvalidator id="ReqFieldVal2"
     controltovalidate="tbAge"
     validationgroup="valGroup1"
     errormessage="Required" runat="Server" />
 
     <br /><br />
        <asp:button id="Button1" text="Validate"
        causesvalidation=true

     validationgroup="valGroup1" runat="Server" />
        <p>ValidationGroup 2</p>
 
        City<asp:textbox id="tbCity" runat="Server" />
        <asp:requiredfieldvalidator id="ReqFieldVal3"
        controltovalidate="tbCity"
     validationgroup="valGroup2"
     errormessage="Required" runat="Server" />
 
     <br><br>
     <asp:button id="Button2" text="Validate"
     causesvalidation=true

     validationgroup="valGroup2" runat="Server" />
   </form>
</body>
</html>
  Permalink  
Comments
prashant patil 4987 3-Jan-13 22:43pm
   
hey what is the problem with this code..
y u downvote it...??tell me the reason??
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

Please refer the below example for ValidationGroup. Here we have group "a" for button1 and group "b" for button2.

 <asp:textbox id="TextBox2" runat="server" validationgroup="a" xmlns:asp="#unknown"></asp:textbox>
    <asp:requiredfieldvalidator id="RequiredFieldValidator1" runat="server" xmlns:asp="#unknown">
        ControlToValidate="TextBox1" ErrorMessage="RequiredFieldValidator" 
        ValidationGroup="a">
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

hi,

Use Validation group property on required field validator & first button.
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 3 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100