Validate form using page_clientvalidate in asp.net



If you want to check your form is validated or not through javascript using page_clientvalidate

 
 Create a .aspx page in paste this HTML
 
<div class="col-md-12">
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title">Remitter Registration :: Remitter Details</h3>
</div>
<div class="box-body">
<div class="col-md-3">
<label for="exampleInputEmail1">
First Name
<asp:RequiredFieldValidator runat="server" ErrorMessage="*" ForeColor="Red" ValidationGroup="Request" ControlToValidate="InputFirstName"></asp:RequiredFieldValidator>
</label>
<asp:TextBox ID="InputFirstName" class="form-control" runat="server" placeholder="First Name" ValidationGroup="Request" AutoCompleteType="Disabled"></asp:TextBox>
</div>
<div class="col-md-3">
<label for="exampleInputEmail1">
Last Name
<asp:RequiredFieldValidator runat="server" ErrorMessage="*" ForeColor="Red" ValidationGroup="Request" ControlToValidate="InputLastName"></asp:RequiredFieldValidator>
</label>
<asp:TextBox ID="InputLastName" class="form-control" runat="server" placeholder="Last Name" ValidationGroup="Request" AutoCompleteType="Disabled"></asp:TextBox>
</div>
<div class="col-md-3">
<label for="exampleInputEmail1">
Mobile
<asp:RequiredFieldValidator runat="server" ErrorMessage="*" ForeColor="Red" ValidationGroup="Request" ControlToValidate="InputMobile"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator runat="server" ForeColor="Red" ValidationGroup="Request" ControlToValidate="InputMobile" ErrorMessage="Invalid mobile no" ValidationExpression="[0-9]{10}"></asp:RegularExpressionValidator>
</label>
<asp:TextBox ID="InputMobile" class="form-control" runat="server" placeholder="Remitter mobile" ValidationGroup="Request" MaxLength="10" MinLength="10" AutoCompleteType="Disabled"></asp:TextBox>
</div>
<div class="col-md-3">
<label for="exampleInputEmail1">
Pincode
<asp:RequiredFieldValidator runat="server" ErrorMessage="*" ForeColor="Red" ValidationGroup="Request" ControlToValidate="InputPinCode"></asp:RequiredFieldValidator>
</label>
<asp:TextBox ID="InputPinCode" class="form-control" runat="server" placeholder="Remitter Pincode" ValidationGroup="Request" AutoCompleteType="Disabled"></asp:TextBox>
</div>
<div class="col-md-3">
<label for="exampleInputEmail1">
Address
<asp:RequiredFieldValidator Enabled="false" runat="server" ErrorMessage="*" ForeColor="Red" ValidationGroup="Request" ControlToValidate="InputAddress"></asp:RequiredFieldValidator>
</label>
<asp:TextBox ID="InputAddress" class="form-control" runat="server" placeholder="Remitter Address" ValidationGroup="Request" Rows="1" TextMode="SingleLine" AutoCompleteType="Disabled"></asp:TextBox>
</div>
<div class="col-md-3">
<label for="exampleInputEmail1">
City
<asp:RequiredFieldValidator Enabled="false" runat="server" ErrorMessage="*" ForeColor="Red" ValidationGroup="Request" ControlToValidate="InputCity"></asp:RequiredFieldValidator>
</label>
<asp:TextBox ID="InputCity" class="form-control" runat="server" placeholder="Remitter city" ValidationGroup="Request" AutoCompleteType="Disabled"></asp:TextBox>
</div>
<div class="col-md-3">
<label for="exampleInputEmail1">
State
<asp:RequiredFieldValidator Enabled="false" runat="server" ErrorMessage="*" ForeColor="Red" ValidationGroup="Request" ControlToValidate="InputState"></asp:RequiredFieldValidator>
</label>
<asp:TextBox ID="InputState" class="form-control" runat="server" placeholder="Remitter state" ValidationGroup="Request" AutoCompleteType="Disabled"></asp:TextBox>
</div>
</div>
<div class="box-footer">
<div class="col-md-12">
<asp:LinkButton runat="server" class="btn btn-primary btn-social btn-sm" OnClientClick="return RetailerRemitterValidation();" ValidationGroup="Request"><i class="fa fa-save"></i>Submit</asp:LinkButton>
<asp:LinkButton runat="server" class="btn btn-danger btn-social btn-sm" PostBackUrl='javascript:history.back()'><i class="fa fa-undo"></i>Back</asp:LinkButton>
</div>
</div>
</div>
</div>
 
After added HTML, add this javascript,
 
it will check your form is validate or not, or you can do - show popup after validation on client-side.  it will resolve many problems 
 
<script>
function RetailerRemitterValidation() {
if (Page_ClientValidate('Request')) {
return true;
}
return false;
}
</script>
 
 
 

0 Comment's

Comment Form

Submit Comment