Click here to Skip to main content
15,893,923 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a no of textboxes and 2 buttons in a form. I want to apply validation to one of them on one button's click and not on second. please help.
Posted
Comments
[no name] 26-Oct-12 1:58am    
What do you mean by "apply validation to one of them on one button's click and not on second" ? Explain little more.
[no name] 26-Oct-12 2:01am    
eg.
[txtbox to save data]
[txtbox to sava data]
[button(add more)]-> i want validation on this button's click not at end

txtboxes
..
..
[button{submit}]
ridoy 26-Oct-12 2:09am    
what type of validation?
[no name] 26-Oct-12 2:12am    
required field validation
[no name] 26-Oct-12 2:11am    
are you working in ASP.Net or windows form.

The CausesValidation property specifies if a page is validated when a Button control is clicked.

Page validation is performed when a button is clicked by default.

This property is mostly used to prevent validation when a cancel or reset button is clicked.

syntex:
<asp:Button CausesValidation="TRUE|FALSE" runat="server" />


example:

XML
<form runat="server">
 <asp:Button id="button1" runat="server"
 CausesValidation="FALSE" Text="Cancel" />
 </form>



more refrence "

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.causesvalidation.aspx[^]

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.causesvalidation.aspx[^]


Thanks,
Ambesha
 
Share this answer
 
Validation groups allow you to organize validation controls on a page as a set. Each validation group can perform validation independently from other validation groups on the page.

You create a validation group by setting the ValidationGroup property to the same name (a string) for all the controls you want to group. You can assign any name to a validation group, but you must use the same name for all members of the group.
ASP.NET
<form id="form1"  runat="server">

   <h3>Button.ValidationGroup Example</h3>

   <asp:label id="NameLabel" xmlns:asp="#unknown">
     text="Enter your name:"
     runat="Server"
     AssociatedControlID="NameTextBox">
   </asp:label>

    

   <asp:textbox id="NameTextBox" xmlns:asp="#unknown">
     runat="Server">
   </asp:textbox>

    

   <asp:requiredfieldvalidator id="RequiredFieldValidator1" xmlns:asp="#unknown">
     controltovalidate="NameTextBox"
     validationgroup="PersonalInfoGroup"
     errormessage="Enter your name."
     runat="Server">
   </asp:requiredfieldvalidator>

   <br /><br />

   <asp:label id="AgeLabel" xmlns:asp="#unknown">
     text="Enter your age:"
     runat="Server"
     AssociatedControlID="AgeTextBox">
   </asp:label>

    

   <asp:textbox id="AgeTextBox" xmlns:asp="#unknown">
     runat="Server">
   </asp:textbox>

    

   <asp:requiredfieldvalidator id="RequiredFieldValidator2" xmlns:asp="#unknown">
     controltovalidate="AgeTextBox"
     validationgroup="PersonalInfoGroup"
     errormessage="Enter your age."
     runat="Server">
   </asp:requiredfieldvalidator>

   <br /><br />

   <!--When Button1 is clicked, only validation
   controls that are a part of PersonalInfoGroup
   are validated.-->
   <asp:button id="Button1" xmlns:asp="#unknown">
     text="Validate"
     causesvalidation="true"
     validationgroup="PersonalInfoGroup"
     runat="Server" />

   <br /><br />

   <asp:label id="CityLabel">
     text="Enter your city of residence:"
     runat="Server"
     AssociatedControlID="CityTextBox">
   </asp:label>

    

   <asp:textbox id="CityTextBox">
     runat="Server">
   </asp:textbox>

    

   <asp:requiredfieldvalidator id="RequiredFieldValidator3">
     controltovalidate="CityTextBox"
     validationgroup="LocationInfoGroup"
     errormessage="Enter a city name."
     runat="Server">
   </asp:requiredfieldvalidator>

   <br /><br />

   <!--When Button2 is clicked, only validation
   controls that are a part of LocationInfoGroup
   are validated.-->
   <asp:button id="Button2">
     text="Validate"
     causesvalidation="true"
     validationgroup="LocationInfoGroup"
     runat="Server" />

 </asp:button></asp:button></form>

Source[^]

this is a working example. :
Validation group[^]
 
Share this answer
 
v3
Comments
fjdiewornncalwe 26-Oct-12 8:54am    
When you copy/paste something, you should provide the source so that you aren't tagged as a plagiarizer.
[no name] 26-Oct-12 9:04am    
I never mentioned that it is coded/developed/written by me.
fjdiewornncalwe 26-Oct-12 16:39pm    
It works the other way around. If you copy/paste something from somewhere else, you need to provide a link to the source so that credit goes where it should. I have taken the liberty of adding that to your answer so that you see what I mean. Cheers.
[no name] 28-Oct-12 3:11am    
Aye Aye Captain. And thanks for adding the source.
SQL
The ValidationGroup property specifies which group of control is validated on validation.

This property is mostly used when there are several buttons in a form.


Simple Examples:
Validation Group Sample[^]

Validation_group_in_ASPNet[^]
 
Share this answer
 

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