Solved

How to determine if asp.net validate control has reported an error?

Posted on 2012-03-29
3
458 Views
Last Modified: 2012-03-31
I have a basic ASP.NET C# web application.  Each control is paired with a validator control and the errors are displayed to the user via "validation summary" control. The Web page has a next button to go to another aspx page.  How do I check in the code behind the Next button if errors exist and not go to the next page?
MSDN shows the ValidatorSummary has a "HasErrors" property.  However, this is not a valid property.

on NEXT button
if no errors go to next page
otherwise redisplay the current page.

thanks
0
Comment
Question by:wilfordrocks
3 Comments
 
LVL 4

Assisted Solution

by:VictorTarasov
VictorTarasov earned 100 total points
ID: 37782739
Use Page.IsValid
Read
0
 
LVL 9

Assisted Solution

by:TonyReba
TonyReba earned 100 total points
ID: 37783526
Well , if you are using the asp validation controls, it should not go to next page, unless you the validation arguments are valid....



As Victor Suggested you can also do;

   protected void btnSubmit_Click(object sender, EventArgs e)
    {
        // If Page is Valid          
        if (Page.IsValid )
        {  

            // Redirect Page 2

           Response.Redirect("Page2.aspx");
        }

    }
0
 
LVL 7

Accepted Solution

by:
Lalit Chandra earned 300 total points
ID: 37784207
ASP.NET 2.0 validator control render a javascript file in which there is a function
ValidatorValidate(validatorcontrolid).
It is this function that actualy gets fired for each validator control on the clientside.
So, on the client side i.e in javascript you can explicitly call this function to validate forcely.
And at the server side, you have to use
Page.IsValid property as suggested by VictorTarasov.

Hope this will make you clear idea about the asp.net Validation at client side.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

777 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