.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

multiple button and validation control

Posted By: priya     Posted Date: May 29, 2009    Points:2   Category :ASP.Net
I have one asp.net webpage in that form i have 3 submit buttons and 10 text boxes. and all the text box have validation control.
When user press 1st button and first 3 text boxes should be validate.

But the problem is all the textboxsex validation is raised.

How to do when user press 1st button only 1st 3 text boxes should be validated.?

i am using asp.net and C# and requiredfieldvalidator control to validate textbox.

Thanks in advance

Author: Suresh             
Posted Date: May 30, 2009     Points: 5   

Make causevalidation in to false in properties of Button, whatever button u dont want to raise the validation.

All the Best

Author: Athira Sreejith             
Posted Date: June 01, 2009     Points: 5   


For the first 3 textboxes u give one validationgroup.and same validation group u give for 1st button.so while validating time first button will validate only that three textboxes.try it like this..

Author: TotalDotNet             
Posted Date: August 16, 2010     Points: 5   

Also try using

The single event can be fired on more than one button click. This is possible through the use of Command button. By setting the CommandName property, you can associate command name with a Command Button. The Command Name is like an identity for a button. Instead of onClick event onCommand event is used in Command button. The Command Name of a Button control could be access through CommandEventArgs instance, which is one among the parameter of an event handler for the Click event.

<asp:Button ID="btn1" runat="server" Text="Submit1" onCommand="btn_Command" CommandName="Command1"/>

<asp:Button ID="btn2" runat="server" Text="Submit2" onCommand="btn_Command" CommandName="Command2"/>

There are two Command Button with their associated Command name Command1 and Command2 respectively. Both of them have btn_Command as an event handler for the Click event.

If the form have more than one Button control and the form is being validated using the Button click event, The CausesValidation validation property enables you to decide the Button among these Button control responsible for validating the form. For the Button control that needs to disable this behavior, set the property CausesValidation as false.

The code example has two Command Button Controls with their associated command name Command1 and Command2 respectively. Instead of using onClick event onCommand event is used in Commandbutton . There is single btn_Command event handler associated with Click event for both of them. The value of CommandName is access through CommandEventArgs instance, which is one among the parameter btn_Command.


Code Behind

// fires on button click
protected void btn_Command(Object sender, CommandEventArgs e)
lblText.Text="commandName is " + e.CommandName;

Aspx Page

<head id="Head1" runat="server">
<title>Button Demontration Page</title>
<form id="form1" runat="server">
<br />
<br />
<br />
//Command Button control associated with command name 'Command1'
<asp:Button ID="btn1" runat="server" Text="Submit1" OnCommand="btn_Command" CommandName="Command1" /></center>
<br />
<br />
//Command Button control associated with command name 'Command2'
<asp:Button ID="btn2" runat="server" Text="Submit2" OnCommand="btn_Command" CommandName="Command2" /></center>
<br />
<br />
<asp:Label ID="lblText" runat="server"></asp:Label></center>

See The Demo»

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend