validate Client-Side, Two Vaidation Groups by ONE Button's Click Event


I am having a form which contains TWO TextBoxes, TWO RequiredFieldValidators, TWO Validation SummaryControls  which are assigned to ValidationGroup named  'group1' and 'group2' respectively. Form also contains ONE Button control, on Button's Click event (Client-Side),                               I want to Validate Both Validation Groups.

Please tell me, How could it be Possible ? 

My Code is as follows :

<form id="form1" runat="server">


<asp:ValidationSummary ID="Val1" HeaderText="h1" runat="server" ValidationGroup="group1" />

<asp:ValidationSummary ID="Val2" HeaderText="h2" runat="server" ValidationGroup="group2" />

<asp:TextBox ID="txt1" ValidationGroup="group1" runat="server" />

<asp:RequiredFieldValidator ID="req1" ValidationGroup="group1" ControlToValidate="txt1" ErrorMessage="err1" runat="server">*</asp:RequiredFieldValidator>

<asp:TextBox ID="txt2" ValidationGroup="group2" runat="server" />

<asp:RequiredFieldValidator ID="req2" ValidationGroup="group2" ControlToValidate="txt2" ErrorMessage="err2" runat="server">*</asp:RequiredFieldValidator>

<asp:Button ID="btn1" runat="server" Text="ClickMe" CausesValidation="true" />



8/10/2007 11:52:41 AM 24353 articles. 2 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 44
Get it on Google Play
Get it on Apple App Store

If you want to validate both groups, why do you have 2 groups to start with?  Just use one validation group.

Darrell Norton, MVP
Darrell Norton's Blog

Please mark this post as answered if it helped you!
8/10/2007 12:22:13 PM

Becuase I have to show HeaderText alongwith Error Messages.

8/10/2007 12:55:52 PM

Hi ysrbpl

If you don’t mind validating from the server side, please refer to the following code.

<html xmlns="" >
<head runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">
        <asp:ValidationSummary ID="Val1" runat="server" HeaderText="h1" ValidationGroup="group1" />
        <asp:ValidationSummary ID="Val2" runat="server" HeaderText="h2" ValidationGroup="group2" />
        <asp:TextBox ID="txt1" runat="server" ValidationGroup="group1">
        <asp:RequiredFieldValidator ID="req1" runat="server" ControlToValidate="txt1" ErrorMessage="err1"
        <asp:TextBox ID="txt2" runat="server" ValidationGroup="group2">
        <asp:RequiredFieldValidator ID="req2" runat="server" ControlToValidate="txt2" ErrorMessage="err2"
        <asp:Button ID="btn1" runat="server" CausesValidation="true" Text="ClickMe" OnClick="btn1_Click" />

*********** code behind
        protected void btn1_Click(object sender, EventArgs e)

            if (req1.IsValid && req2.IsValid)


Benson Yu
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help. This can be beneficial to other community members reading the thread.
8/15/2007 10:04:03 AM

Similar Artilces:

Firing both Client side event and server side event for server side button
I am having some difficulties getting this to work.. I have button_click ( and ClientClick (Javascript).  Javascript is firing fine.  Server script is not. may be you have return return false in the in the javascript which is why its not firing server side event.You should add javascript evelt like thisbutton1.onclientclick = "functionname" Function should nopt return false. Vikram www.vikramlakhotia.comPlease mark the answer if it helped you...

How to access Client Side control in server side button click event?
Hi all, I need to access client side control from server side code. For an example <form id="form1" runat="server"> <table> <tr> <td>UserName:</td> <td><input type="text" id="textBoxUserName" /></td> <td><asp:Button ID="buttonShow" runat="server" Text="show" OnClick="buttonShow_Click" /></td> </tr> </table>   </form> I need to access the textBoxUsername in the server side button click event. How to do that? Than...

client side click handler / server-side command event doesn't fire
I am rewriting an old control of mine to be more AJAX-friendly. It is a subclass of Button that disables itself when clicked, so that the user can't, say, double post a credit card payment. I have some javascript code for the prototype including this: _onClick : function(e) { if(this.get_element() && !this.get_element().disabled && this._DisableAfterClick == true) { this.get_element().disabled = true; if (this._DisabledText != null && this._DisabledText.length > 0) { this.get_element().value = this._DisabledText; } } //this.get_element().form.s...

Calling Button Click Event From Another Event With Client Side Code
Hi All,I am trying to call a (server control) button's click event from another event where the button has a client side code as well. I defined my button as: <asp:Button runat="server" id="button1" onclick="button1_Click" onclientclick="someJSFunction(); return false;" text="..." />  The button1_Click event does not contain any server side code, I just need a reference for my other event to call to, like so: void OtherEvent(object sender, EventArgs e) { button1_Click(sender, e);}  What happens is that button1_Click is being fired but the client side code ...

Validation Controls in .NET ( Client side or server side?)
 i have a very basic question. We have all these validation controls in ( required field, range validator and others) question is the required field validator is a server side control. So does that mean that it does a post back? it client side or server side control  The only controls that post back are buttons and other inputs where you set AutoPostback="True", such as a dropdownlist or a textbox.  Another way of posting back is using an UpdatePanel and placing a trigger in it for a specified control and/or event. All controls are considered clien...

Is it possible to redirect client's browser from the client side?
What I'm getting at is this. My server doesn't have access to certain websites. But my client's browsing my site will have access from the computers they're using. Can my programming logic somehow open up a restricted access site by routing the command to the client's browser and then out on to the web? Or is the best I can do simply putting a hyperlink up that the user can click on? Thanks for any help. To perform any action on the client you will need to consider using a client-side language such as Javascript. You would then be able to do something like document.location('url to re...

Calling server side sub from client side button click
Hi, I have some javascript in my page, and a function within that, which is run when the client side form is submitted. What I need is for that function to run, which updates a server side variable, then following that a server side sub should run, using that (newly updated) variable. I have currently set it up with the  onsubmit= tag of the client side form running the first (JavaScript) function, and then the submit button at the bottom of the client side form calling the server side sub with its onClick property. The (probably quite daft!) thinking behind that was that the on...

Call server-side page function from client-side button click
I have an existing ASP application that I am migrating to In the ASP app I was using the Microsoft.XMLHTTP on a the client-side of a ASP page to retrieve data from another asp page using the Microsoft.XMLDOM object. The client page passes 3 tags columns, table and Criteria. The receiving page builds the SQL statement executes the query and returns the row with all the column data. I am trying to convert it over to ASP.NET and I am getting errors on the xmlDOM.Load(Request.InputStream) on DLookup.aspx, the code is listed below. Someone suggested to use System.Net HTTP classes su...

what client-side and server-side events are fired when button X is hit?
Folks,In a web aspx page, I use a client-side (javascript) button named "Cancel" so when users hit it, if the data they enter is not saved yet, then this client-side button prompts users to save data before the page is closed. I code this client-side button with event "onclick" and thing like <input type=button ... onclick="btnCancelClick();" >   My question is if users hit the right top corner button X (next to the maximize and minimize buttons also on the top right corner of the aspx web window page), then what client-side (javascript) and serv...

Server side validation affecting client side validation
Hi there I have some client side validation that is working fine and enables/disables buttons based on user selections. This works great. However, when I perform server side validation using custom validators (like checking if the user has entered < HTML > tags or decimals in the integer boxes) and the server side validation returns isValid = false then all of the JavaScript validation that I've already done when the user clicked each control is lost. I don't understand why the enabled/disabled state of the control is not maintained.  What is calling the JavaScr...

client side validation vs server side validation
hello  i see a web form that consists of three controls :textbox,requiredfieldvalidator that weired to the textbox and a button within the click event of the button there is the following: if page.isvalid then response.redirect("Page is valid") else response.redirect("Page is not valid") end if according to my understandings: when the user does not fill anything in the textbox and then clicks the button the the page will not be submitted (i.e no request to the page will be happened or no postback will be happened) then no server event will be happened so it is sure when the us...

Server Side Validation vs Client Side Validation
If your page is using client side validation for required fields, expressions, etc.     What are the benefits or disadvantages of using 'extra' server side validation for max lengths, parsing, etc? Both have their Advantages and Disadvantages... so give this a read Regards,Vinz"Code, Beer and Music" that's my way of being a programmer!How to get your Forum Question Answered | Blog | CodeASP.NET hi there, advantage: because you are using javascript some browsers for any reason may not sup...

Firing server side validation & Client side confirm with a single button..
Hi All, I have a "Update" asp button. onclick of the button i need to check the server side validations like:if (!IsValidEmail(ctrlEmailAddress.TextBoxControl.Text.Trim())) {MessageBox.Show("Enter valid email address"); validateCheck = false; } After completion of this type of validations, i need to fire one javascript confirmbox saying "Are you sure you want to update this order?" with "Yes/No" options. All these things needs to be done in a single button click. Can any one help me to acheive this ..requirement?  -HemanthPlease rem...

how two developer can work on a same project (one on client side and other on admin side)
how to two developer work on a same project (one on client side and other on admin side).I don't wan't to use team server.We have to work on vs 2003.Kamran ShahidSr. Software Engineer(MCP,,,MCTS,[web])Netprosys Inc.www.netprosys.comRemember to click "Mark as Answer" on the post that helps U...

downloading .NET dll's to client side
hi! does anyone knows how can I download .NET assembly to the client side using the <Object> tag with vesioning? I tried using : <OBJECT id="MyUserControl" style="WIDTH: 1000px; HEIGHT:800px" codeBase="MyUserControl.dll#1,0,0,0" classID="MyUserControl.dll#MyNamespace.MyClass"> </OBJECT> but my MyUserControl.dll assembly is dependent on several other .net dll which should be download indirectly as well. It works fine. The problem arises when I advance the MyUserControl.dll AssemblyVersion (and his dependent dll a...

RangeValidator's client side validation of CurrencyDecimalDigits
When I set the Type="Currency" on a range validator, on the server side it properly fails 1.000 because for en-US the NumberFormatInfo.CurrencyDecimalDigits is 2, and from within BaseCompareValidator.ConvertCurrency a regular expression is made like this:  string pattern = @"^\s*([-\+])?((\d{1,3}(\,\d{3})+)|\d*)\.?(\d{0,2})\s*$"; The same expression is also made in the WebUIValidation.js file however the javascript version allows for 3 digits to be valid and then fails at 4.  Has anyone else seen this?  Is there somewhere else I should submit t...

firing server side button click from client event
Hi, Is it possible to fire button_click (server side event ) from client side event like page_load etc. Why I need this because I am doing post back on a page and showing some auditing data  to the user. Once the user clicks on the back button (on browser) it says page has expired. Is there any way of avoiding page expiration. It says cannot submit the information. need to refresh etc. Is there any way that when user goes back I fire that submit event myself from client side onload event. Or will it still show page has expired before even my client side onloa...

Client side validations happen when image button clicked.
Hi I have an image button placed in a table. When I click that button it opens a browser using javascript. At the same time all the validations on the parent form displays the error messages. Is there a way that I can click this image button and the validations on the parent page does not happen? Thanks in advance. You can set the CausesValidation property of the image buttonto false, and no validation will execute when it is clicked, hope this does the trick, sivilianMy Weblogs Hello This worked. Thank you very much. I have another question regarding this issue. ...

ISSUE WITH Control's behaviour inisde UPDATE PANEL
 hii evry1..,             i have an strange chk it out..                      aspx page:            < asp:UpdatePanel ID="OUpdatePanel" runat="server" >                <ContentTemplate>             &nbs...

executing server side code and client side (javascript) code simultaneously while clicking a button
how to execute server side code and client side (javascript) code simultaneously while clicking a button in You can't. When clicking a button: the client-side executes, the page does a PostBack, then the server-side executes.NC... what if i want to update a database and then open a new windows is it possible with

Client Side validation of Calendar control prior to server side selectionchanged event code
Hello, Any thoughts or suggestions regarding this will be greatly appreciated. I have a Calendar control with the validation constraint(can't enter appointments on Holidays or on Thursdays). To create a smoother experience, I'd like for this to be done client side. The dillema is how can I intercept or precede the <asp:calendar> controls selectionchanged event from firing and run my client javascript; passing it to the server if validation succeeds for more intensive processing and database activity. The clientside javascript will need the selected date to deter...

avoiding redundant server-side validation after client-side validation
I see an inaccurate validation behavior on my (2.0) form. The EnableClientScript property of my validation control is set to True by default, so it performs the validation on clientside. But as soon as this occurs, it also performs the server-side validation, so the page refreshes. When the validation error occurs on clientside, it should not do the validation on serverside (I'm not calling Page.Validate() or doing Page.IsValid). In my past experience, handled this automatically, but I guess it's not always the ca...

How do I capture the textbox's text for client-side validation?
Hi!  Using VS 2008, ASP.NET page. Content placeholder 1 is in the Body tag and 2 is in the Header tag of the master page used by the .aspx. I have a text control called txtEmail in a table in ContentPlaceHolder1 in the .aspx page.  The CustomValidator's ClientValidationFunction is set to cvCheckEmail.  I am using "source" and "client_args" (because that is what I see in a training manual I have.)  I am  assuming (eek!) that the source and arguments are available.  What I am trying to do is to capture the email address th...

Help with client side events Vs. server side events
Hi, Can someone look as the following script and tell me why marking the check box doesn't generate a client side event eventhough there's: onclick="checkClick()"? marked.  Thanks in advance, Sivan <%@ Page Language="c#" %><HTML> <HEAD>  <meta name="vs_targetSchema" content=""> </HEAD> <body>  <SCRIPT language="c#" runat="Server">  void Page_Load(object s, EventArgs e) {  if (!Page.IsPostBack)  {   Label1.Text = Label...