asp.net - 设置默认按钮输入 - 母版页

标签 asp.net

大家好,我有下一个问题。当我按 Enter 时,我必须将一个按钮设置为默认按钮。我可以在表单中使用 DefaultButton,因为现在我的所有页面都继承自母版页,并且我有来自母版页的内容,但这是行不通的。有人可以给我任何替代方案来解决这个问题。谢谢

最佳答案

根据 Enter Key - Default Submit Button :

ASP.NET 2.0 introduces a wonderful work around for this. By simply specifying the "defaultbutton" property to the ID of the , whose event you want to fire, your job is done.

The defaultbutton property can be specified at the Form level in the form tag as well as at panel level in the definition tag. The form level setting is overridden when specified at the panel level, for those controls that are inside the panel.

Also, the Event Handler for the specified button, fires thereby simulating a true submit button functionality.

像这样

<form id="form1" runat="server" defaultbutton="Button1">
<div>
<asp:Button ID="Button1" runat="server" Text="Button1" OnClick="Button1_Click" />
</div>

或者你可以通过

Page.Form.DefaultButton = crtlLoginUserLogin.FindControl("LoginButton").UniqueID

或者只是

Page.Form.DefaultButton = LoginButton.UniqueID

这会起作用。

关于asp.net - 设置默认按钮输入 - 母版页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21461599/

相关文章:

c# - ASP.NET 在发布到 IIS 后失去与 SQL Server Express 的连接

c# - 如何从 .Net 窗口应用程序读取 web.config

c# - ASP.NET MVC 5 Identity with Model First

asp.net - 对于新项目,经典 ASP 是否仍然是替代其他语言的替代品?

c# - 可点击的 Web 控件,ASP.NET

javascript - 如何在asp.net中使用javascript将按钮html回发到服务器

javascript - 如何使用 "next"按钮选择 Bootstrap 选项卡。我遵循了其他答案但没有工作

c# - 如何从 JavaScript 调用方法背后的代码

C# EF Deep Lambda 非重复计数查询

c# - 为 SEO 规范化我的网页 URL