Avatar of Cognize
Cognize

asked on 

Need to check for ASP.NET Validation result client side (before hits the server)...

Hi,

I've noticed a bug where a user is able to click the submit button on a form twice before the page returns, which is having an unwanted affect. Why the page is allowed to submit twice (cutting off the processing of the previous request - I'm not sure).

I've seen similar posts, which suggest disabling the button with javascript. This is what I'm doing for now essentially, but with a timer to re-enable the button if the form doesn't validate client side. This is a less than perfect solution though.

The reason I have to disable and re-enable client side, is that if the form validation fails client side, I have to re-enable the button so the user can edit input and re-submit using the code below.

What id prefer is a way of checking validation results in code, on the client side, so I can disable on the initial click, and then re-enable if the form validation fails, so the user can have another go.

Does anyone know how to test for this?
function disableButton() {
 
                                        var buttonDiv = document.getElementById('regBtnDiv');
                                        buttonDiv.style.visibility = "hidden";
                                        buttonDiv.style.height = "0px";
 
                                        var msgDiv = document.getElementById('validatingMessage');
                                        msgDiv.style.visibility = "visible";
                                        msgDiv.style.height = "20px";
                                        
                                        setTimeout('showButton()', 2000);
                                    }
 
                                    function showButton() {
 
                                        var buttonDiv = document.getElementById('regBtnDiv');
                                        buttonDiv.style.visibility = "visible";
                                        buttonDiv.style.height = "auto";
 
                                        var msgDiv = document.getElementById('validatingMessage');
                                        msgDiv.style.visibility = "hidden";
                                        msgDiv.style.height = "0px";
                                    }

Open in new window

ASP.NETJavaScriptAJAX

Avatar of undefined
Last Comment
Cognize
Avatar of cdittberner
cdittberner
Flag of Germany image

How do you validate? If you are using AJAX to validate the form, all you have to do is to return also a "negative" result to the callback-handler to re-enable the button.
ASKER CERTIFIED SOLUTION
Avatar of DropZone
DropZone
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Cognize
Cognize

ASKER

Cheers for that, it put me on the right track. I ended up with

if (Page_ClientValidate() == true) {

                                          ...do stuff

                                        }
ASP.NET
ASP.NET

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

128K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo