0

我在这里看到了很多与这个问题非常接近的问题,但没有一个似乎适合这个特定的场景。

描述:我在主页面中有带有登录按钮的 ID 和密码字段。这些在“LoginValidationGroup”中并且工作正常。

现在,在 Default.aspx 中,我有一个电子邮件文本框和提交按钮,它们位于“NotifyMeValidation”组中,它们也可以工作,但如果你按下回车键而不是提交按钮,它们就不行了。提交按钮工作正常 - 输入键......不是那么多。

Enter 键会导致在 LoginValidationGroup 上进行验证,即使 TextBox 设置为 CausesValidation="true",并且它位于 NotifyMeValidation 组中。

我保证人们会在该框中输入电子邮件并按 Enter。我会!!!当他们这样做时,他们会在顶部看到一个标注气球,告诉他们需要用户 ID。

我的错误是什么?如果我需要发布实际代码,我可以这样做。

实际上,让我继续做吧。

从 Default.aspx:

<asp:RequiredFieldValidator 
    runat="server"
    ValidationGroup="NotifyMeValidation"
    ID="EmailRequiredValidator"  
    ControlToValidate="SenderEmailTextBox"
    ErrorMessage="Email is Required" 
    Display="None" />
<ajaxToolkit:ValidatorCalloutExtender 
    runat="Server"
    PopupPosition="Left"
    ID="EmailRequiredValidatorExtender"
    Width="185px"
    TargetControlID="EmailRequiredValidator" 
    WarningIconImageUrl="/Images/warning.gif" />
<asp:Label ID="SenderEmailLabel" runat="server" ssociatedControlID="SenderEmailTextBox" EnableViewState="false" Text="Email:"></asp:Label>&nbsp;&nbsp;
<asp:TextBox ID="SenderEmailTextBox" runat="server" ValidationGroup="NotifyMeValidation" Width="350" BackColor="#cccccc" CausesValidation="true"></asp:TextBox>
<br /><br />
<asp:Button ID="SubmitButton" runat="server" ValidationGroup="NotifyMeValidation" EnableViewState="false" CssClass="submit" Text="Send" CausesValidation="true" OnClick="btnSubmit_Click" />

从母版页:

<asp:Label CssClass="LoginHeading" ID="UserNameLabel" runat="server" AssociatedControlID="UserNameTextbox">UserName:&nbsp;</asp:Label>
<asp:TextBox CssClass="LoginTextBox" ID="UserNameTextbox" runat="server"  ValidationGroup="LoginValidation" CausesValidation="True"></asp:TextBox>&nbsp;
<asp:Label CssClass="LoginHeading" ID="PasswordLabel" runat="server" AssociatedControlID="PasswordTextbox">Password:&nbsp;</asp:Label>
<asp:TextBox CssClass="LoginTextBox" ID="PasswordTextBox" runat="server" TextMode="Password" ValidationGroup="LoginValidation" CausesValidation="True"></asp:TextBox>&nbsp;
<asp:Button CssClass="LoginHeading" ID="LoginButton" runat="server" Text="Button" CommandName="Login"  ValidationGroup="LoginValidation" CausesValidation="True" onclick="LoginButton_Click" />

母版页验证器...

<asp:RequiredFieldValidator runat="server" ID="UIDRequired"
    ValidationGroup="LoginValidation"   
    ControlToValidate="UserNameTextbox"  
    Display="None"  
    ErrorMessage="<b>Required Field Missing</b><br />A User ID is required." />  
<ajaxToolkit:ValidatorCalloutExtender 
    runat="Server"
    ID="UIDValidationExtender"
    PopupPosition="Left"
    Width="185px"
    TargetControlID="UIDRequired" 
    WarningIconImageUrl="/Images/warning.gif" />
<asp:RequiredFieldValidator runat="server" ID="PWRequired"   
    ValidationGroup="LoginValidation" 
    ControlToValidate="PasswordTextbox"  
    Display="None"  
    ErrorMessage="<b>Required Field Missing</b><br />A password is required." />
<ajaxToolkit:ValidatorCalloutExtender 
    runat="Server"
    ID="PWValidationExtender"
    PopupPosition="Left"
    TargetControlID="PWRequired" 
    Width="185px"
    WarningIconImageUrl="/Images/warning.gif" />
<asp:CustomValidator 
    runat="server" 
    Display="None"
    ValidationGroup="LoginValidation" 
    ID="CustomUserExistsValidator"
    ControlToValidate="UserNameTextbox" 
    ErrorMessage="<b>Invalid UserID!</b><br />User ID doesn't exist. Please try again.<br />"
    OnServerValidate="CustomCheckUserExists"/>
<ajaxToolkit:ValidatorCalloutExtender 
    runat="server" 
    PopupPosition="Left"
    ID="UserIDCalloutExtender"
    TargetControlID="CustomUserExistsValidator"
    Width="185px"
    WarningIconImageUrl="/Images/warning.gif" />
<asp:CustomValidator 
    runat="server" 
    ID="CustomPWValidator"
    Display="None"
    ValidationGroup="LoginValidation" 
    ControlToValidate="PasswordTextbox" 
    ErrorMessage="<b>Invalid Password!</b><br />Please try again.<br />"
    OnServerValidate="CustomValidatePassword"/>
<ajaxToolkit:ValidatorCalloutExtender 
    runat="server" 
    PopupPosition="Left"
    ID="PWCalloutExtender"
    TargetControlID="CustomPWValidator"
    Width="185px"
    WarningIconImageUrl="/Images/warning.gif" />
<asp:CustomValidator 
    runat="server" 
    ID="CustomUserApprovedValidator"
    Display="None"
    ValidationGroup="LoginValidation" 
    ControlToValidate="UserNameTextbox" 
    ErrorMessage="<b>Approval Error!</b><br />This UserID exists, but is not yet approved.<br />"
    OnServerValidate="CustomCheckUserApproved"/>
<ajaxToolkit:ValidatorCalloutExtender 
    runat="server" 
    PopupPosition="Left"
    ID="UserApprovedCalloutExtender"
    TargetControlID="CustomUserApprovedValidator"
    Width="185px"
    WarningIconImageUrl="/Images/warning.gif" />
4

2 回答 2

3

尝试<asp:Panel>在每组控件周围添加一个,并将该DefaultButton属性设置为用户点击时要单击的按钮的 ID Enter

于 2013-03-12T19:44:19.137 回答
1

只是为了解释这里发生了什么,当您在文本框上按 enter 时,会触发 aspx 的默认按钮。为了处理这个问题,您可以在文本框上单击回车键时触发一些 jQuery 代码,然后此代码将执行您需要的特定按钮的单击。检查这个

于 2013-03-12T19:47:38.140 回答