?
Solved

One more try: Execute javascript only if ASP.NET form IsValid = true!

Posted on 2007-08-10
8
Medium Priority
?
1,310 Views
Last Modified: 2008-01-09
Thought i had this issue solved, guess i didn't...

I have a ASP.NET, with .Net validators on the page. I have a Javascript function that fires onclikc of the submit button of the form. How do i prevent the javascript from running the the ASP.NET form is InValid?

This does not work:
---------------------------------------------------------------------------------------------------------------------
        if (Page_ClientValidate() == true)
        {
                document.getElementById('ProgressIndicator').style.display='inline';
                document.getElementById('AppInterface').style.display='none';
        }
----------------------------------------------------------------------------------------------------------------------

This does not work:
---------------------------------------------------------------------------------------------------------------------
        if (Page_IsValid == true)
        {
                document.getElementById('ProgressIndicator').style.display='inline';
                document.getElementById('AppInterface').style.display='none';
        }
----------------------------------------------------------------------------------------------------------------------

Nugs
0
Comment
Question by:Nugs
  • 4
  • 3
8 Comments
 
LVL 9

Expert Comment

by:Raju Srivatsavaye
ID: 19672556
Checking for validation of the page should be something like this..I think
Page.IsValid
0
 
LVL 2

Author Comment

by:Nugs
ID: 19672577
That is server side check... I need the client side javascript check on the page validation...
0
 
LVL 14

Expert Comment

by:NBSO_ISS
ID: 19672590
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 14

Expert Comment

by:NBSO_ISS
ID: 19672604
You need to use...
Page.Validate("MyValidationGroup");

The example is in the link...
0
 
LVL 2

Author Comment

by:Nugs
ID: 19672668
ok... to clarify here... Server side code behind is NEVER executed if the page is not validated by the ASP.NET validation controls... These validation controls use the JAVASCRIPT page_IsValid marker to track if the page is valid or not on the CLIENT SIDE.

The JAVASCRIPT i originally posted does not work even though i have read time and time again that ASP.NET uses Page_IsValid to track page validation and can be used in custom javascript to check if the poage is valid or not..........

Again: Server side code is never run. Page.IsValid is not what i am looking for here. I need to catch if the page is valid or not in my JAVASCRIPT that is being executed.

Nugs
0
 
LVL 14

Accepted Solution

by:
NBSO_ISS earned 1500 total points
ID: 19672741
Sorry, I skimmed your question.  I should have read more carefully...

http://aspnet.4guysfromrolla.com/articles/051204-1.aspx

This tells you how to do it... Make sure you read the part titled...

"Fixing ASP.NET's Validation Controls to Support Client-Side Validation for Modern, Non-Microsoft Browsers"
0
 
LVL 2

Author Comment

by:Nugs
ID: 19673039
Very interesting article, but this has to be simplified a little.

.NET uses it own client side code to validate controls. If the validation methods return false (invalid) it has to be able to be cought simply, right? like:

if(page_isvalid){
//do something
}

?

Why does the seem so difficult?

Nugs
0
 
LVL 2

Author Comment

by:Nugs
ID: 19673133
after playing around with it some, i managed to get this to work:

        if (Page_ClientValidate() == true)
        {
                document.getElementById('ProgressIndicator').style.display='inline';
                document.getElementById('AppInterface').style.display='none';
        }

now this javascript function will only fire if the client validation returns true. Have no clue why it did not work before.

Thanks for the input

Nugs
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month16 days, 18 hours left to enroll

864 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