开发者

asp.net - trigger updatepanel on pressing the return key

开发者 https://www.devze.com 2023-04-08 22:54 出处:网络
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 d

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>
0

精彩评论

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

关注公众号