开发者

WebForms submitting specific form with enter key (not clicking)

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 --%>    
&开发者_如何学Clt;/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?


The panel control allows you to define a default button within the scope of it's contents:

<asp:Panel runat="server" DefaultButton="submitButtonA">
 <asp:LinkButton ID="submitButtonA" runat="server" Text="Submit A"/>
</asp:Panel>

<asp:Panel runat="server" DefaultButton="submitButtonB">
 <asp:LinkButton ID="submitButtonB" runat="server" Text="Submit A"/>
</asp:Panel>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜