CODEDIGEST
Home » CodeDigest
Search
 

Technologies
 

Fire Validator Controls Before JavaScript Confirm Box Fires in ASP.Net Page
Submitted By Satheesh Babu B
On 1/4/2009 8:15:04 AM
Tags: ASP.Net,CodeDigest,JavaScript  

Fire Validator controls Before JavaScript Confirm Box Fires in ASP.Net Page

 

Consider, we have validator control on our page with a JavaScript Confirm box attached to a submit button. Clicking Submit will fire the Confirm box and if we select yes it will take us to the server without firing the validator control. This behavior is seen because the return value true from the javascript confirm box will override the Validator control behavior in client side and pass the control to server.

 

Read my article to understand more about the client side functionalities of ASP.Net Validator controls.

 

Restrict Asp.Net Validator controls to Fire on Page Submit

 

Handling Validations Effectively With Validation Controls in ASP.Net Projects

 

To overcome this behavior and to fire validator controls we can use the following javascript code snippet.

 

function ConfirmSubmit()

{

Page_ClientValidate();

if(Page_IsValid) {

return confirm('Are you sure?');

}

 return Page_IsValid;

}

 

<asp:Button ID="btnSave" runat="server"

                        OnClientClick="javascript:return ConfirmSubmit()" OnClick="btnSave_Click" Text="Save" />

Do you have a working code that can be used by anyone? Submit it here. It may help someone in the community!!

Recent Codes
  • View All Codes..