代码:
form1.AcceptButton = accessButton;
我把:
using System.Windows.Forms;
但它没有找到它。它说System.Web.UI.HtmlControl.HtmlForm
没有这个定义。嗯?
System.Windows.Forms 和 System.Web.UI 是两个完全不同的系统。Windows 窗体用于创建桌面应用程序,System.Web.UI 用于创建 ASP.NET 页面。您不能在 ASP.NET 中使用 WinForms。
请参阅ASP.NET 上的此处。
将控件放在面板中并设置DefaultButton
:
<asp:Panel DefaultButton="accessButton" runat="server">
<asp:TextBox id="myname" runat="server" />
<asp:Button id="accessButton" Text="Submit" runat="server" />
</asp:Panel>
改为使用Page.Form.DefaultButton
。