当调用 Page_ClientValidate 将 isValid 设置为 true 时,以下代码不会隐藏“信息”DIV 并显示“问题”DIV。如果我将 isValid 设置为 true 或 false,它会按预期工作。
为什么 Page_ClientValidate 会阻止隐藏/显示行为的发生?
function hide() {
var isValid = Page_ClientValidate('validInfo');
if (isValid) {
if (!$('[id$=chkConfirm]').is(':checked'))
{ alert("Please confirm and agree with conditions"); }
else {
$('#info').hide();
$('#questions').show();
}
}
}
这是 HTML - 我将其缩短为主要部分,DIVS 中只有更多的 txtBoxes 和 radioLists:
<div id="info">
<asp:TextBox ID="tBoxTradingName" runat="server" Width="200"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="tBoxTradingName"
ValidationGroup="validInfo">Required</asp:RequiredFieldValidator>
<asp:CheckBox ID="chkConfirm" Text=" I confirm that the information provided above is accurate."
runat="server" />
<asp:Button ID="btnNext" Text="Next >>" runat="server" OnClientClick="hide()" Width="100"
CausesValidation="true" ValidationGroup="validInfo" />
</div>
<div id="questions" style="display:none;">
<div class="label">
Do you trade as a
</div>
<asp:RadioButtonList ID="rBtnTradeAs" runat="server">
<asp:ListItem>Sole Proprietor</asp:ListItem>
<asp:ListItem>Company</asp:ListItem>
<asp:ListItem>Closed Corporation</asp:ListItem>
<asp:ListItem>Trust</asp:ListItem>
<asp:ListItem>Other (please specify)</asp:ListItem>
</asp:RadioButtonList>
<asp:TextBox ID="txtBoxTradeAs" runat="server" Width="200"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator30" runat="server" ControlToValidate="rBtnTradeAs"
ErrorMessage="Required">
</asp:RequiredFieldValidator>
</div>