10

我有一个标准的 asp:login 控件:

<asp:Login ID="mbLogin" runat="server" TitleText=""
  DestinationPageUrl="~/Default.aspx"
  PasswordRecoveryText="Forgot your password?"
  PasswordRecoveryUrl="~/LostPassword.aspx"></asp:Login>

在 Internet Explorer 中,按 Enter 不会提交表单,但 IE 会快速向我发出 10 次哔哔声。在其他浏览器中,Enter 工作得非常好,并按照您的预期提交论坛。

我已经看到了这个问题,但这仅在您拥有带有实际按钮的实际表单元素而不是整个登录控件时才有效。

为什么它在 IE 中被阻止(为什么由于某种原因被阻止了 10 次)?有解决方法吗?

4

4 回答 4

10

在您的登录控件的设计器中:“转换为模板”。然后在页面加载中通过找到LoginButton设置表单的defaultButton

ASPX:

<form id="form1" runat="server">
    <div>
        <asp:Login ID="Login1" runat="server" OnAuthenticate="Login1_Authenticate">
            <LayoutTemplate>
                <table border="0" cellpadding="1" cellspacing="0" style="border-collapse: collapse;">
                    <tr>
                        <td>
                            <table border="0" cellpadding="0">
                                .....
                                <tr>
                                    <td align="right" colspan="2">
                                        <asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In" ValidationGroup="Login1" />
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </LayoutTemplate>
        </asp:Login>
    </div>
    </form>

代码隐藏:

    protected void Page_Load(object sender, EventArgs e)
    {
        Button lbButton = Login1.FindControl("LoginButton") as Button;
        form1.DefaultButton = lbButton.UniqueID;
    }
于 2010-07-13T13:23:05.623 回答
0

这是一个 hack,但它可以解决您的 Internet Explorer 问题。
向您的页面添加一个隐藏在视图中的文本框。

<!-- Hack for Internet Explorer browsers to allow the page to post back when the enter key is pressed-->
<asp:TextBox ID="txtIEHackBox" runat="server" style="visibility: hidden; display: none;" />

这将导致 Internet Explorer 在按 Enter 后发回 Button Web 控件的名称/值对。

于 2010-07-13T13:21:43.803 回答
0
Button lbButton = Login1.FindControl("LoginButton") as Button;

ContentPlaceHolder contentPlaceHolder = (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1");
contentPlaceHolder.Page.Form.DefaultButton = lbButton.UniqueID;
于 2012-02-05T11:18:09.507 回答
0

我知道这是一篇超级旧的帖子,但另一种方法是使用asp:PanelwithDefaultButton设置为用户通常单击以登录的按钮的 ID:

<asp:Login ID="LoginUser" runat="server">
  <LayoutTemplate>
    <asp:Panel ID="LoginPanel" runat="server" DefaultButton="LoginButton">
      <other stuff here like username and password textboxes>
      <asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In"/>
  </asp:Panel>
</LayoutTemplate>

于 2013-05-13T15:23:45.647 回答