Asp.net定义了输入按钮动作

时间:2016-09-14 02:19:49

标签: c# asp.net

我的网页上有2个按钮。当我按下#34;输入"时,它会自动执行" close_topic"但我想让我的输入按钮执行" button_click&#34 ;

 <asp:Button ID="btnLogout" Text="Close Topic" OnClick="close_topic" runat="server" />

 <asp:Button ID="ButtonTT" Text="Click" runat="server" OnClick="button_click" />

protected void button_Click(object sender, EventArgs e)
{

}

protected void close_topic(object sender, EventArgs e)
{

}

尝试使用<asp:Panel ID="Panel1" runat="server" DefaultButton="ButtonTT">,但无效。

1 个答案:

答案 0 :(得分:1)

您是否围绕2个按钮包裹了面板?如下:

<asp:Panel ID="Panel1" runat="server" DefaultButton="ButtonTT">
    <asp:Button ID="btnLogout" Text="Close Topic" OnClick="close_topic" runat="server" />
    <asp:Button ID="ButtonTT" Text="Click" runat="server" OnClick="button_click" />
</asp:Panel>

修改

基于how to set a default 'enter' on a certain button,您也可以使用代码执行此操作:

Me.Form.DefaultButton = Me.btn.UniqueID;

Me.Page.Form.DefaultButton = = Me.btn.UniqueID;

用您的网页名称替换Me.Page