I have multiple RequiredFieldValidator such as:
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtbox1"
Display="Dynamic" ErrorMessage="Required Field" SetFocusOnError="True"
ValidationGroup="validator1" CssClass="validator" />
Linked to this button:
<asp:LinkButton runat="server" ID="btnNext1" Text="Next Page" CssClass="btn" ValidationGroup="validator1" />
Along with some javascript:
<script type="text/javascript">
$(function() {
function nextPage1() {
$( "#divFirstPage" ).hide("fade");
$( "#divSecondPage" ).show("fade");
$( "#<%=btnNext1.ClientID%>" ).hide();
$( "#<%=btnNext2.ClientID%>" ).show();
$( "#<%=btnPrevious1.ClientID%>" ).show();
};
$( "#<%=btnNext1.ClientID%>" ).click(function() {
nextPage1();
return false;
});
$( "#divSecondPage" ).hide();
$( "#divThirdPage" ).hide();
$( "#<%=btnNext2.ClientID%>" ).hide();
$( "#<%=btnPrevious1.ClientID%>" ).hide();
$( "#<%=btnPrevious2.ClientID%>" ).hide();
});
</script>
But the javascript gets executed before the validations, so id need to execute the validations before the javascript
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
If my understanding is correct, you want to validate your form before executing javascript code
Try something like this:
$( "#<%=btnNext1.ClientID%>" ).click(function() {
var val = Page_ClientValidate();
if(!val) {
return false;
}
nextPage1();
return true;
});
Optionally if you want to specify a custom ValidationGroup, you can use the following code:
Page_ClientValidate('your group name');
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0