requiredfieldvalidator not working onclientclick

May 24, 2016


Requiredfieldvalidator not working onclientclick added in button.

Code  : This code will not execute required field validator

 <asp:Button ID="btnSubmit" runat="server" Text="Check" 
OnClientClick="javascript:return confirm('Are you sure to Submit?')"
 ValidationGroup="Submit" />

use Page_ClientValidate() predefined function to avoid issue.

Solution :

 <asp:Button ID="btnSubmit" runat="server" Text="Check" 
OnClientClick="return CheckToProceed();"
 ValidationGroup="Submit" />

Javascript ::

function CheckToProceed() {
 if (Page_ClientValidate()) {
return confirm('Are you sure to Submit?')

Reference : stackoverflow

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: