Client-side validation works, but server-side does not.

Hey all,

I have got this text box control on my webform, which has two validators.. 1. RegularExpressionValidator and 2. CustomValidator.

Now, RegularExpressionValidator control works if I enable client-script. But somehow it does not work for server-side validation. Any idea why this is happening? This happens to another textbox control on other web form as well which has similar coding. So, to enable the validation at present I can only do client-side validation I guess.



1    <TD>
2    		<anthem:TextBox id="txtDatePlannedSurgery" CssClass="aspText" Runat="server" AutoCallBack="false"
3    		Columns="12" TabIndex="53" AutoUpdateAfterCallBack="True"></anthem:TextBox>
4    </TD>
5    </TR>
6    <tr>
7    <td colspan="2" align="left" valign="top">
8    		<anthem:RegularExpressionValidator ID="surgeryDate_RegVal" AutoUpdateAfterCallBack="true" runat="server" ControlToValidate="txtDatePlannedSurgery"
9    		ValidationExpression="\d{1,2}\/\d{1,2}\/\d{4}" ErrorMessage="Please enter date in dd/mm/yyyy format only" EnableClientScript="true"
10             ValidationGroup="preoperativeValidation" CssClass="errorControlText" Display="dynamic"></anthem:RegularExpressionValidator>
11   </td>
12   </tr>
13   <tr>
14   <td colspan="2" align="left" valign="top">
15   		<anthem:CustomValidator ID="surgeryDateCustom" runat="server" AutoUpdateAfterCallBack="true"
16              ErrorMessage="Please enter valid date" Enabled="true" ControlToValidate="txtDatePlannedSurgery"
17              CssClass="errorControlText" Display="dynamic" Visible="true" EnableClientScript="false"
18              ValidationGroup="preoperativeValidation" OnServerValidate="dateValidationCall"></anthem:CustomValidator>
19  </td>
20  </tr>






1/11/2007 12:57:27 AM 93655 articles. 6 followers. Follow

8 Replies

Similar Articles

[PageSpeed] 47

i was thinking to explain to you

but i think you will understand more by read yourself

James Wu (MIB426)
.NET is only way to go
1/11/2007 3:45:06 AM


Paste the server side code too.



Plz mark this post as marked if it helps.

Senior MSCRM Consultant,
Orion Enterprise,
Sydney, 2000
1/11/2007 4:42:06 AM

Ummm.. for regularexpression validator, there is no server side code that I have written. Its just default regularexpression validator control. Say, its original asp control instead of anthem control.


1/11/2007 5:37:59 AM

i was thinking to explain to you

but i think you will understand more by read yourself


That was quite informative, but didn't really helped me in solving my problem :( Could you throw some light where I am missing out..


1/11/2007 5:39:30 AM

Make sure you test Page.IsValid is true inside your button's Click event handler method. If you post back from a control other than a button or the button has CausesValidation=false, call Page.Validate() first.

Another article for this:  (I wrote it, so I know it addresses the issues I'm presenting.)

--- Peter Blum
Creator of Peter's Data Entry Suite (formerly Professional Validation And More and Peter's Date Package) and Peter's Polling Package
1/11/2007 7:44:55 PM

That's true. In my code-behind what I'm doing now is, 

I've set button's CauseValidation property to false. I am also checking for Page.IsValid property in my button click event. And before that I'm calling Page.Validate() method. I'm trying to debug and see what happends in there. But I couldn't figure out why RegularExpression is not getting validated.

Same thing works in other test page.  Is there a way that I can track when the regularexpression validator checks for validation on postback while debugging. I pressed F11 for debugging line-by-line when Page.Validate() method called, but all it showed was going through all control's visible property.

Any ideas...





1/12/2007 5:49:17 AM

okey here i'm gonna put something which I find interesting...

So, I have RegularExpressionValidator and CustomValidator on my textbox control..

I had a method that gets executed for custom validation. While I was debugging Page.Validate(), I noticed that custom validation method gets executed first and then it moves on. I'm not sure though when RegularExpressionValidation occurs.

Now, in custom validation method, I was dealing with the string value entered in textbox, which I expected in dd/mm/yyyy format and was under impression that if custom validation occurs on this text box that means it has passed regular expression validation which is not the case. So, I put a try catch block in my method and then debugged it again. This time, I let whole button click method execute, and when I saw on my page, it actually had error message for Regular expression validator..


So, does that mean, custom validation always gets performed before regular expression validation? Can't I make it in a way that if regular expression validator first evaluates and if it fails, it doesn't go for custom validation, and displays that message?

 I am posting my custom validation method here just for reference:


public bool isValidDate(string datearg)
        string dtCh = "/";
        int minYear = 1800;
        int maxYear = 2100;
            int pos1 = datearg.IndexOf(dtCh);
            int pos2 = datearg.IndexOf(dtCh, pos1 + 1);

            string strDay = datearg.Substring(0, pos1);
            string strMonth = datearg.Substring(pos1 + 1, pos2 - (pos1 + 1));
            string strYear = datearg.Substring(pos2 + 1);

            if (strDay.StartsWith("0") && strDay.Length > 1)
                strDay = strDay.Substring(1);

            if (strMonth.StartsWith("0") && strMonth.Length > 1)
                strMonth = strMonth.Substring(1);

            if (datearg.Length > 10)
                return false;
            // year has to be in 4 digit. otherwise return false.
            if (strYear.Length != 4)
                return false;
            // date must be in the defined format. i.e. dd/mm/yyyy
            if (pos1 == -1 || pos2 == -1)
                return false;

            int day = int.Parse(strDay);
            int month = int.Parse(strMonth);
            int year = int.Parse(strYear);

            if (strDay.Length < 1 || day < 1 || day > 31 || (month == 2 && day > getDaysInFeb(year)) || day > getDaysInMonth(month))
                return false;
            if (strMonth.Length < 1 || month < 1 || month > 12)
                return false;
            if (strYear.Length != 4 || year == 0 || year < minYear || year > maxYear)
                return false;
        catch (Exception e)
            return false;

        return true;



Please give your thoughts about this..




1/12/2007 6:34:29 AM

I had a similar problem, and in particular I was using the Anthem framework, just as you were. The validation didn't seem to be firing. It turns out that it was, but I simply wasn't checking the Page.IsValid property in my Button_OnClick method, as PLBlum above suggested.

Ujjaval, since the source for your Button_OnClick method isn't shown, it's tough to be sure, but I'll reiterate that you want to follow the practice detailed here:


7/9/2008 4:48:08 AM

Similar Artilces:

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

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

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

When do the validators kick in? Are they server side or client side?
 Hello,I am confused. I was under the impression that validators work on the client side.But I was confused when I set the enabled property of validator to false and then the validator did not work. (RegularExpressionValidator1.Enabled = false;)But the other confusing thing to me is that if the validators  work on the server side then when don't i see the page refresh like on other postback events? Kindly throw some light.Thanks!   Validators always work on the server side (assuming they're enabled), but also work on the client side if EnableClientScript is t...

I wonder if this is the right forum to post this question because it is an issue about both server and client side processing. I am developing a web application (online store) which will run in a hosting company. Users accessing this app will be able to place orders with one limitation; the store has a schedule to accept orders. For example, it can be open from 8AM to 10PM and/or it can be closed on Mondays. I just can't validate time and/or day directly because time zone may lead to wrong results. So I thought about getting the schedule information, which is saved in my database, ...

Validation Conrols: Client Side or Server Side?
Hi Folks, I am just wondering if the validation controls, use javascript...or server side code behind...Clearly, I would prefer it be server-side, because i'm concerned that a potential evil-doer could by-pass the validation, by turning off JS.If the validation controls use JS --- can someone refer me to proper server side validation techniques (VB). Thanks, - Joel    "The truth is rarely pure and never simple."- Oscar Wilde, The Importance of Being Earnest ASP.NET validation controls always use server-side validation, with additional client-side...

Web resources about - Client-side validation works, but server-side does not. -

Client-side scripting - Wikipedia, the free encyclopedia
... different and changing content depending on user input, environmental conditions (such as the time of day), or other variables. Client-side ...

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: 11/27/2015 5:31:43 AM