asp.net - trigger updatepanel on pressing the return key
I have a page with an updatepanel which contains a small login form - it runs fine when the user clicks on the submit button, but if the user presses the return key after entering their password, it does not run.
Here's the code...
开发者_Go百科<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="loginButton" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:TextBox ID="username" MaxLength="11" runat="server" />
<asp:TextBox ID="password" MaxLength="64" runat="server" TextMode="Password" />
<asp:LinkButton ID="loginButton" OnClick="Submit_login" runat="server" Text="<img src='login.png' alt='Login' />" />
</ContentTemplate>
</asp:UpdatePanel>
If you add a panel in the Content template and assign the DefaultButton
, it should submit the button when a user hits Enter.
<ContentTemplate>
<asp:panel id="p" runat="server" defaultbutton="loginButton">
//Form here with loginButton
</asp:panel>
</ContentTemplate>
Put your the controls that are inside <ContentTemplate>
inside an Panel
and set it's default button to be loginButton.
Like this:
<asp:Panel id="defaultPanel" runat="server" DefaultButton="loginButton">
<asp:TextBox ID="username" MaxLength="11" runat="server" />
<asp:TextBox ID="password" MaxLength="64" runat="server" TextMode="Password" />
<asp:LinkButton ID="loginButton" OnClick="Submit_login" runat="server" Text="<img src='login.png' alt='Login' />" />
</asp:Panel>
精彩评论