Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


CustomValidator Question

Posted on 2011-10-26
Medium Priority
Last Modified: 2012-05-12
I have a textbox where date of birth is entered. Requirement is that the date of birth be at least 16 years of age. So I have a custom validator with an
OnServerValidate method that does a comprison and returns whether the args.isvalid property is true or false. Now obviously if the method returns a false I want processing to stop and a message to be shown to the user that the dob need to be a least 16 years.

The problem I have right now is not that the code doesn't work right. It does work.(When I set break points and watch it execute, everything seems to run as planned) However, the page just continues to process ! No good ! It just runs through my OnServerValidate method, evaluates to a false, and then keeps going. It eventually redirects to a new page because thats what happens in the subsequent  events. How do Iactually get this to stop processing when the  OnServerValidate method evaluates to false? What am I missing here?
//from .aspx markup

 <asp:TextBox ID="tbDOB1" runat="server" Width="35%"  MaxLength="10" />
 <asp:CustomValidator ID="CheckAgeValidator" runat="server" ControlToValidate="tbDOB1" CssClass="FieldValidatorError"  ErrorMessage="Age must be greater than or equal to 16 years." 

//from codebehind

    protected void CheckAgeValidator_ServerValidate(object source, ServerValidateEventArgs args)
        DateTime enteredAge = DateTime.Parse(tbDOB1.Text);

        // is the person at least 16
        if (DateTime.Now.Date.AddYears(-16) >= enteredAge)
            args.IsValid = true;

            args.IsValid = false;



Open in new window

Question by:jazzcatone
LVL 75

Accepted Solution

käµfm³d   👽 earned 2000 total points
ID: 37031529
Check the Page.IsValid property before executing other code. This is set by your args.IsValid = ... assignment.

Author Closing Comment

ID: 37031895
Yep that did it. Thanks

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question