client-side and server-side validation reducing post-backs question

For my page I was using server-side validation. In order to reduce post-backs I decided to implement client-side validation -- do the same validation as server (but keep server-side for security reasons). I could not find the answer to this easily -- Does my client-side validation stop post-backs? I've noticed that having one client-side validation does not stop the other server-validations from doing a post-back. Currently I have 5 CustomValidators, all with ClientValidationFunction and OnServerValidate set. When the client script sets args.isValid as false, does it stop the postback from occuring? I could not find an easy way to figure this out. Thanks,



4/14/2009 2:18:17 PM 93655 articles. 6 followers. Follow

13 Replies

Similar Articles

[PageSpeed] 37

Hi Chris,

Try this post

Hope that helps.


Don't forget to click "Mark as Answer" on the post that helped you. This credits that member, earns you a point and marks your thread as Resolved so everyone will know you have been helped.
4/14/2009 7:28:05 PM
Yes, args.IsValid=false, causes that validator to be invalid on the client side. This should stop all postbacks from controls in the save ValidationGroup. Also, you need to set the CausesValidation property to true on the postback controls that you want to validate before posting back.

Hope this helps.
When I answer your question successfully, you are helping me grow by asking it.
4/15/2009 2:43:12 AM


Thank you for the link, but it does not answer my question. They mention that "client side is executed, then server side" which I know -- but my question is if client-side fails, does the post-back still occur causing server-side to kick in, and how this works with multiple validators.



 Thanks for the reply - that is what I wanted to know; it's probably good idea to group my validators.

4/15/2009 4:05:50 PM

Hi Chris,


Yes, if any client side validation fails it stops the page from being posted to the server.
Therefore preventing, useless posts to the server, and giving the user a quicker feedback on the corrections needed.

Now, once all the client-side validators are valid. Then the page is posted to the server…and then all the server side validators fire, as they should, to double check the validation and for obvious security reasons as you mentioned.


You say in you question :
“I noticed that having one client-side validation does not stop the other server-validations from doing a post-back”.

Regarding Custom Validators…If you want them to do a client side check, you need to write custom Javascript for them.
If there is no custom Javascript for them…then obviously they will post to the server, without doing a client check...

If you did write a custom JS function and it’s not picking up on wrong input...that means that your JS function is not properly written…

Did you write custom JS for your Custom Validators?

To be clear, client side validation will not prevent a post-back persee…it prevents
postback if the client validation is failed. Once all is passed…then a post-back occurs, anways...for server side it always should!

So in your case…when you submit the form…obviously all the client side validation  comes out as valid…and then it’s posted to the server…if your custom validators don’t have custom JS function associated with them…then they don’t do client side validation and post straight to the server…I think this is what is happening, in your case…let me know.

- Joel

"The truth is rarely pure and never simple."
- Oscar Wilde, The Importance of Being Earnest
4/15/2009 4:55:31 PM


Thank you for your response. Regarding my comment, "I noticed that having one client-side validation does not stop the other server-validations from doing a post-back"

I have valid JavaScript checking functions. What I was referring to, when I first implemented client-side validation, I only had 1 javascript validation for one control. The rest still had server-side validation. When the one control with client-side had invalid entry, and I clicked submit, all validation errors appeared, not just the one with my client-side validator. This is the reason for my initial inquiry, on whether client-side validation will stop post-backs (as clearly it wasn't stopping the post-backs in this example). My validators setup is as follows:

5 CustomValidators, with no ControlToValidate attribute set, with no ValidatorsGroup attribute set, but with both ClientValidationFunction and OnServerValidate attributes set. When I added them all to the same  ValidatorsGroup, validation stopped altogether. I had some issues when setting the ControlToValidate, as one of the controls is represented as a label which is updated by the server after a web-service is called. I now have all 5 CustomValidators set for both client and server validation, and wanted to make sure that my client-side validations would stop unneccesary post-backs.

I cannot verify this, but this is what I am assuming happens with my setup: Client-side validations are called one by one, independent of eachother. If a client-side fails, nothing will happen (other than error message), and moves on to next client-validation. If at least one of the client-side validations sets isValid = true, then after all client-side validations run, a post-back will be made. At this point server-validation occurs and proceeds from there. Is this assumption correct?

4/15/2009 6:38:25 PM

As a test I removed the OnServerValidate fields, and having done that, no validations are performed. Apparently my Client-side validations aren't doing much. Here is one of my javascript validators:


1    function ValidateEvaluatee(sender, args) {
2      if (ctlEvaluateeLbl == null || ctlEvaluateeLbl.innerHTML == "[Please select a Person]") {
3        args.isValid = false;
4      }
5      else { args.isValid = true; }
6    }

 And the corresponding aspx CustomValidator:

1    <asp:CustomValidator runat="server" ErrorMessage="Please select a valid user for feedback." CssClass="validation" Display="Dynamic" ID="LblEvaluateeValidator" ClientValidationFunction="ValidateEvaluatee">*</asp:CustomValidator>
4/15/2009 7:05:01 PM


What you are assuming makes much sense. I never had the same situation as you have now, but, it seems that each Javascript function is overwritting the args.isvalid property, as they each run seperately.
So if one functions sets the args.isvalid =false...then the next function will overwrite it to args.isvalid =true.
So as a matter of fact, the only Javascript funtion that actually determines the behavior of the page, is the the last one that runs...

You can get around this problem, by adding a bit of logic to each of your Javascript functions to check if args.Valid has "arrived" to it false already...

As an example:

function validateLength(oSrc, args){

  if (args.isValid =False) {
   // Do nothing, args.isValid remains false
// Check for the validity of lenght and set Args.isValid to appropirate Value


So by adding logic that check the status of the Args.isValid at the beging of your JS functions,.if ever the previous function as determined the validation was will leave it false...!

- Joel

P.S I don't know how if the grammar of this Javascript function is accurate (I don't often write JS) was to give you an idea of the logic to follow...

"The truth is rarely pure and never simple."
- Oscar Wilde, The Importance of Being Earnest
4/15/2009 7:06:30 PM

I do not think it is the case that each javascript function is passed the same isValid (ie - they do not overwrite eachother), though I could be wrong. I just tried your suggestion (correcting some of the javascript grammar), and it doesn't not change anything - no validations take place.

4/15/2009 7:17:29 PM

Ok My Client-Side validation is working now - It turns out that the javascript variable to use is arg.IsValid and not arg.isValid. Needs to have a capital 'I' ;)

Going back to my original question however, I would like to know how client-side validation works with multiple groupped or non-groupped controls, and under which conditions the post-back is stopped or allowed.

4/15/2009 7:26:17 PM

I read the comment you just posted after my last reply.

.1 You need to keep the OnServerValidate fields...otherwise does not know which server side function to call when doing the validation....

.2 For custom validators you don't need to explictely put a "control do validate", since in your custom validation function you can reference anything you like.

.3 Is there a reason why you are using validation groups?
Is you want everything validated on the same page...there is no point of using validation group...
Validation groups are useful if you want some controls validated and anothers not...this maybe explains why when you put things in a validation group it din't check for validity.
This from MSDN"
During postback, the Page class's IsValid property is set based only on the validation controls in the current validation group. The current validation group is determined by the control that caused validation to occur. For example, if a button control with a validation group of LoginForm is clicked, then the IsValid property will return true if all validation controls whose ValidationGroup property is set to LoginForm are valid. Other controls such as a DropDownList control can also trigger validation if the control's CausesValidation property is set to true (and the AutoPostBack property is set to true.) "

The full documentation of validation group are here:

Bottom line, being...if you want everything validated, no need to use validation groups.

- Joel

"The truth is rarely pure and never simple."
- Oscar Wilde, The Importance of Being Earnest
4/15/2009 7:31:49 PM


 1) I had removed the OnServerValidate attributes in order to test if my client-side validation was setup properly and working. I found that it wasn't, and it was because of my typo. I have added it back in so that server calidation occurs.

2) I normally didn't have ControlToValidate, but wanted to include that in my description in case it mattered as far as the CustomValidator control performed differently if set or not (as I don't know specifics about validators).

3) I normally don't use ValidatorGroups, this falls into the same category as the previous -- I had tested it out to see if it would change my results.

End conclusion - I had a typo (should be IsValid and not isValid) which caused my client-side validation to not perform. I wil do some testing and see if I can come back with results of how client and server validations work together.

4/15/2009 8:56:29 PM


Going back to your original question, you should only get a postback if all validators are valid (or all in teh group if using groups).  I thought the post I referred to included a link to, which states:

When the user pushes a button that has the CausesValidation property set to True, the validators are all re-evaluated. If they are all valid, then the form is posted to the server. If there are one or more errors, a number of things happen:

  • The submit is cancelled. The form does not get posted back to the server.
  • Any invalid validators become visible.
  • If there is a validation summary with ShowSummary=true, it will collect all the errors from the validation controls and update its contents with them.
  • If there is a validation summary with ShowMessageBox=true, it will collect the errors and display them in client message box.


Don't forget to click "Mark as Answer" on the post that helped you. This credits that member, earns you a point and marks your thread as Resolved so everyone will know you have been helped.
4/16/2009 12:19:30 AM


 Thanks again for clearing some of this up for me, and shame on me for not having followed through with that link before. This is starting make sense. I just did a test with two controls with validations. One control had client-side and server-side, the other control only had server-side. When both had invalid entries, only the client-side error showed. Once the client-side validation control was corrected, the second control with only server-side displayed an error. Now this works as I would expect. Thanks for your help Aaron.



4/16/2009 1:26:07 PM

Similar Artilces:

problem: client side validation posting back server side in firefox only
Hi I have validation controls and I only want them to validate via client side. It works in IE. But in firefox it does validate client side, however it immediately post backs server side. How can I prevent this?? I have a login control and it works fine there. Only problem it occurs is inside a createuserwizard. I have sumary validation with js pop up. Using 3.5. Before trying to solve the actual problem, please implement server side validation. Consider it a manditory part of validation because: - The user may have a browser not supported by the client-side scripts - T...

form double validation- server side and client side
Hi! I would like to make a server side validation after calling a js function that makes the client-side validation. I do not understand couple of things: 1. Do i need a server side button or  a simple HTML submit button in order to call both of the tests? 2. How do i call a server side function which is written in csharp  after i finish my JS validation (the submit  button is calling the JS function for validation first.)- is it possible to call it directly from a js function? 3. I know that my toolbox on  contains validation controls who probably are b...

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...

Client Side HTML Radio Buttons not Posting with Server Side Form
I have a server side form that is posting when an HTML client side button is clicked.  However, the value of my html client side radio button is null when I call Request.Form("htmlradiobuttonlist") on the resulting page.  Does anyone know why the form won't the post the value?  Please help!  Thanks in advance.I'm still using dot net 1.1.  I can use server side buttons or server side radio buttons.  I can explain why if necessary.Below, you can see the HTML radio buttons in the datalist.  The JS function works, but is omitted from below.<form id="form1" a...

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...

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...

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...

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...

Validations client side or server side ???
Where should the validations (Required field, range, etc.) be done in an web page client side or server side?  As per my knowledge most of the validations are on client side using javascript, unfortunately it won't work if someone has disabled their browsers javascript option. what do we do in this case? Any suggestion please. Both... Client-side for rich client experience. Server-side for data validation and for clients who have disabled javascript. *Always* validate on the server side. You will still get the benefits of client-side validation on browsers setup to handle th...

client side and server side validation\validator8.aspx&font=3 i am trying to do custom validation something similar to the above. I hv done the Severvalidate method in the code behind. What about the client validation? do i do it in code behind or in javascript as shown? The goal is to add text like this to the page:<script language='javascript'>function MyFunction(src, args){  // your logic to set args.IsValid here}</script>ASP.NET doesn't care if you typed it directly in...

Client side or server side validation???
I have multiple usercontrols each displayed by pressing a button and then change the apperance to a new user control and so on. I have to check that almost every field in this user controls have a value entered, and then indicate (e.g. with a red star) those textboxes that does'nt have a value entered. How should I do this in the best way, client side or server side with some validator? I have in mind that when using a server side validator, it may dissapear when making a postback. But I'm not sure, and I assume there is a way to come around this problem?What do you all say? Client side or s...

How to Access/Pass Server Side Array Variable at Another Web Form's Client Side
Hi All,I struck up with some intrested senario at my application development...hope some body will guide me or sends me some code snippets....Thanks in advance.Senario is like A.aspx (using C# .net 2.0 as code behind) I am going to have a array variable basically it is an TWO Dimensional array after populating the values in array I need to redirect/ reload another web form B.aspx, here i need to access the array in B.aspx client side JavaScript.How can I do this...Thanks AgainRaju Dont do a redirect but use server.transfer. That way the previous page will still hold its value, ...

validation, is it better to have client side or use server side validator controls
 Hi All. I want to do validation on text boxes etc. Is it better to do client side validation or just use the server side validation controls?   Hi!  If for server side controls you mean RequiredFieldValidator, CompareValidator, RegularExpressionValidator, etc.. i can tell you that they use client and server validation. For instance if you use a RequiredFieldValidator, on the client will be a validation, but on the server this condition will be evaluated again. Probably one of the objetives of this is deal with client with javascript disabled. Of course I ...

Disabling Client Side and Server Side Validation
I have a page which contains a User ID and Password field which have RequiredFieldValidators against them. The page can also load a User Control which contains another field which also has a RequiredFieldValidator against it. When I submit the form I use the ValidatorEnable function to disable the validator, on the User Control Page, when the user is signing in. This works fine on the client side but the page fails on the server side as I presume it does not know that I have disabled the control from the client side. Can anyone tell me the best way to solve this problem. Thanks M...

Web resources about - client-side and server-side validation reducing post-backs question -

Client-side - Wikipedia, the free encyclopedia
Client-side refers to operations that are performed by the client in a client–server relationship in a computer network . Typically, a client ...

Senior Search Manager - Client Side!!
... strategy insight for senior IT management - resources to understand and leverage information technology. Senior Search Manager - Client Side ...

Account Manager - Client Side - Previous Agency Experience Welcome!!
Computerworld Australia is the leading source of technology news, analysis and tools for IT decision makers, managers and professionals.

Media Sales Executive - Client Side!!
Technology news and reviews for business and home.

PPC Paid Search Manager - CLIENT SIDE
Defining Technology for Australia's IT Leaders. PPC Paid Search Manager - SEM - **CLIENT SIDE** Sydney CBD Location Client side!! SEM/PPC/Paid ...

How Basecamp Next got to be so damn fast without using much client-side UI
When we started working on Basecamp Next last year, we had much internal debate about whether we should evolve the existing code base or rewrite ...

Seven Tips for Pitching From the Client's Side of the Table
I had a chance to sit on the other side of the pitch table. Here is what I learned.

Client-side coding: How to prevent malicious use?
Applications that run on a user-controlled device cannot be perfectly protected.

The client side
... regarding the professionals you seek to assist. Even better if you possess that understanding yourself, having worked on the client side. I'm ...

Ecommerce traffic being hijacked by client side malware
According to new research 15 to 30 percent of eCommerce site visitors are infected with Client Side Injected Malware (CSIM) that causes them ...

Resources last updated: 2/11/2016 11:15:36 PM