Posts Tagged ‘requiredfieldvalidator’

h1

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" 
OnClick="btnSubmit_Click" 
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" 
OnClick="btnSubmit_Click" 
OnClientClick="return CheckToProceed();"
 ValidationGroup="Submit" />

Javascript ::

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

Reference : stackoverflow

Advertisements