Solved

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

Posted on 2012-03-29
3
451 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now