admin管理员组文章数量:1406166
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
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
Share Improve this question edited Jul 18, 2012 at 19:03 Zarichney asked Jul 18, 2012 at 18:55 ZarichneyZarichney 1651 gold badge3 silver badges12 bronze badges 2-
So you want to execute the validators before the code in the
nextPage1
function?? – Jupaol Commented Jul 18, 2012 at 18:59 - yes, sorry for not making that clear – Zarichney Commented Jul 18, 2012 at 19:04
1 Answer
Reset to default 7If 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');
本文标签: aspnetWorking RequiredFieldValidator along with javascriptStack Overflow
版权声明:本文标题:asp.net - Working RequiredFieldValidator along with javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744353310a2602178.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论