我有幾個<asp:Validators>
和一個<asp:ValidationSummary>
一個簡單的WebForms ...asp.net的ValidationSummary
當提交表單,一切正常,一個「*」的旁邊顯示的文本框無效並且ValidationSummary顯示錯誤消息。
問題出在您通過按Enter鍵或點擊鍵而失去焦點在文本框之一上。 (onChange事件)。 驗證程序的'*'如果無效則顯示,但ValidationSummary不顯示。
僅在提交正常行爲期間顯示ValidationSummary?
看起來這是因爲JS的功能,顯示摘要(ValidationSummaryOnSubmit)設計僅在提交功能「Page_ClientValidate」 稱爲但是,這是所有生成的JS等等....
<div class="wrapper">
<h2>
<asp:Label ID="MainStatus" runat="server" CssClass="successNotification"></asp:Label>
</h2>
<form id="form1" runat="server">
<asp:ValidationSummary ID="LoginUserValidationSummary" runat="server" CssClass="failureNotification"
ValidationGroup="LoginUserValidationGroup" />
<asp:Label ID="StatusError" runat="server" CssClass="failureNotification"></asp:Label>
<!-- <asp:Panel ID="pnlMyForm" runat="server" DefaultButton="LoginButton"> -->
<fieldset class="login" runat="server" id="FormFieldset">
<legend>Account Information</legend>
<p>
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">Username:</asp:Label>
<asp:TextBox ID="UserName" runat="server" CssClass="textEntry"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName"
CssClass="failureNotification" Display="Dynamic" ErrorMessage="User Name is required." ToolTip="User Name is required."
ValidationGroup="LoginUserValidationGroup">*</asp:RequiredFieldValidator>
</p>
<p id="CurrentPwd" runat="server">
<asp:Label ID="CurrentPasswordLabel" runat="server" AssociatedControlID="CurrentPassword">Current Password:</asp:Label>
<asp:TextBox ID="CurrentPassword" runat="server" CssClass="passwordEntry" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="ConfirmPasswordValid" runat="server" ControlToValidate="CurrentPassword"
CssClass="failureNotification" Display="Dynamic" ErrorMessage="Current Password is required." ToolTip="Current password is required."
ValidationGroup="LoginUserValidationGroup">*</asp:RequiredFieldValidator>
<asp:CompareValidator ID="ConfirmPasswordComp" runat="server" ControlToCompare="Password"
ControlToValidate="CurrentPassword" CssClass="failureNotification" Display="Dynamic"
Operator="NotEqual" ErrorMessage="The current password and new password must be different."
ValidationGroup="LoginUserValidationGroup">*</asp:CompareValidator>
</p>
<p id="Pwd" runat="server">
<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password" Height="21px">New Password:</asp:Label>
<asp:TextBox ID="Password" runat="server" CssClass="passwordEntry" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator Display="Dynamic" ID="PasswordRequired" runat="server" ControlToValidate="Password"
CssClass="failureNotification" ErrorMessage="New Password is required." ToolTip="New Password is required."
ValidationGroup="LoginUserValidationGroup">*</asp:RequiredFieldValidator>
</p>
<p id="ConfirmPwd" runat="server">
<asp:Label ID="ConfirmPasswordLabel" runat="server" AssociatedControlID="ConfirmPassword">Confirm Password:</asp:Label>
<asp:TextBox ID="ConfirmPassword" runat="server" CssClass="passwordEntry" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ControlToValidate="ConfirmPassword" CssClass="failureNotification"
Display="Dynamic" ErrorMessage="Confirmation Password is required." ID="ConfirmPasswordRequired"
runat="server" ToolTip="Confirmation Password is required." ValidationGroup="LoginUserValidationGroup">*</asp:RequiredFieldValidator>
<asp:CompareValidator ID="PasswordCompare" runat="server" ControlToCompare="Password"
ControlToValidate="ConfirmPassword" CssClass="failureNotification" Display="Dynamic"
ErrorMessage="The password was not correctly confirmed. Please ensure that the new password and confirmed password match exactly."
ValidationGroup="LoginUserValidationGroup"> </asp:CompareValidator>
</p>
</fieldset>
<p class="right">
<input id="ResetButton" runat="server" type="reset" value="Clear fields" />
<asp:Button ID="LoginButton" runat="server" Text="Update Password" OnClick="Button_Update_Pwd"
ValidationGroup="LoginUserValidationGroup" />
<asp:Button ID="UsrButton" runat="server" Text="Next" OnClick="Button_Check_User"
ValidationGroup="LoginUserValidationGroup" />
</p>
<!-- </asp:Panel> -->
</form>
</div>