0

我有两个表单,每个表单都有按钮,我已经通过两个面板将它们抽象出来,所以当按下每个面板中的输入键时,将发送正确的按钮。在一个面板中,我有登录表单

 <asp:Panel ID="pnlRegistered" runat="server" DefaultButton="btnLoginButton">
    <LayoutTemplate>
       <asp:Button ID="btnLoginButton" runat="server" CommandName="Login" Text="Login" ValidationGroup="Login1" OnClick="btnLoginButton_Click"  ClientIDMode="Static" />
    </LayoutTemplate>
 <asp:Panel>

但我得到了例外

System.InvalidOperationException

The DefaultButton of 'pnlRegistered' must be the ID of a control of type IButtonControl.
4

2 回答 2

2

您缺少 DefaultButton 的值:

<asp:Panel ID="pnlRegistered" runat="server" DefaultButton="btnLoginButton">
  <asp:Button ID="btnLoginButton" runat="server" CommandName="Login" Text="Login" ValidationGroup="Login1" OnClick="btnLoginButton_Click"  ClientIDMode="Static" />
<asp:Panel>

编辑:您还可以在代码隐藏中设置 DefaultButton,如下所示:

pnlRegistered.DefaultButton = btnLoginButton.UniqueID;
于 2013-06-14T19:53:33.227 回答
1

将您的面板放在layouttemplate您的登录控件中

<asp:Login ID="Login1" runat="server">
    <LayoutTemplate>
        <asp:Panel ID="pnlRegistered" runat="server" DefaultButton="btnLoginButton">
            <asp:Button ID="btnLoginButton" runat="server" CommandName="Login" Text="Login" ValidationGroup="Login1"
                ClientIDMode="Static" />
        </asp:Panel>
    </LayoutTemplate>
</asp:Login>
于 2013-06-14T20:01:11.147 回答