Solved

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

Posted on 2012-03-29
3
461 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

733 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