WebForms 使用 Enter 键提交特定表单(而不是点击)
假设我有一个整页表单,但在表单内,提交时需要发生两个或多个事件:Login
& Register
Site.Master:
<%@ Master Language="C#" AutoEventWireup="true"
EnableViewState="true" CodeBehind="Site.Master.cs"
Inherits="Site.SiteMasterPage" %>
<!doctype>
<html>
<head runat="server">
<%-- stuff --%>
</head>
<body>
<form ID="MainForm" action="" runat="server">
<asp:Login id="LoginControl" runat="server" />
<asp:CreateUserWizard id="RegisterControl" runat="server" />
</form>
</body>
</html>
如果我的光标聚焦在 asp:Login
的 input type="text"
内,并且我点击了 Return (关闭 javascript),页面提交,但我没有登录。
当我尝试注册(填写 createUserWizard 并点击 Return 键时,也会发生同样的情况实际点击的“注册”,触发一些事件)
是否有任何非 JavaScript 解决方案可以让 Return 键提交表单中正确的、当前聚焦的部分?
Say I have one full-page form, but within the form, there are two or more events that need to take place on submission: Login
& Register
Site.Master:
<%@ Master Language="C#" AutoEventWireup="true"
EnableViewState="true" CodeBehind="Site.Master.cs"
Inherits="Site.SiteMasterPage" %>
<!doctype>
<html>
<head runat="server">
<%-- stuff --%>
</head>
<body>
<form ID="MainForm" action="" runat="server">
<asp:Login id="LoginControl" runat="server" />
<asp:CreateUserWizard id="RegisterControl" runat="server" />
</form>
</body>
</html>
If my cursor is focused inside of an input type="text"
for asp:Login
, and I hit Return (with javascript off), the page submits, but I am not logged in.
The same thing happens when I attempt to register (filling out the createUserWizard and hitting the Return key instead of actually clicking "Register", firing some event)
Is there any non-JavaScript solution for getting the Return key to submit the proper, currently focused portion of the form?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
面板控件允许您在其内容范围内定义默认按钮:
The panel control allows you to define a default button within the scope of it's contents:
默认按钮听起来今晚可能是你的朋友 - http://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmlform.defaultbutton.aspx
实际上可能不是,我还没有尝试过没有 JavaScript。
The default button sounds like it might be your friend tonight - http://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmlform.defaultbutton.aspx
Actually it might not be, I haven't ever tried it with no Javascript.