views:

92

answers:

1

I have an ASP button for which I have set the OnClientClick property to display a javascript confirm message. However, I only want this message to be displayed AFTER all of the client side validations have passed.

How can I do this? Essentially, I believe that I need to force Page level validation from the client and then, only if it passes, display the confirmation box.

+1  A: 

If you're using the ASP.NET validation controls add an OnClientClick like this to your submit button...

<asp:Button ID="blah" OnClientClick="if(Page_ClientValidate())return confirm('your message')" OnClick="your submit method" Text="submit" runat="server" />

...Page_ClientValidate() will return true if the page is validated then you need to return the results of your "confirm" in order for the form to be submitted.

There's something along these lines available here: http://www.codeproject.com/KB/aspnet/JavascriptValidation.aspx

soutarm