Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a form submit with a LinkButton?

My login usercontrol has two text boxes and a linkbutton.

<asp:TextBox id="tbUserName" runat="server" size="10" />
<asp:TextBox id="tbPassword" runat="server" TextMode="Password" size="10" />

<asp:LinkButton Text="login" CssClass="submit"  runat="server" ID="lbLogin" OnClick="btnLogin_OnClick" />

I would like to call the "btnLogin_OnClick function when someone pushes enter on tbUsername or tbPassword.

How do I do this?

like image 473
Nate Avatar asked Aug 27 '11 20:08

Nate


1 Answers

Here's a neat trick:

<asp:Panel ID="pnlLogon" runat="server" DefaultButton="lbLogin" Width="100%" >
        <asp:TextBox id="tbUserName" runat="server" size="10" />
        <asp:TextBox id="tbPassword" runat="server" TextMode="Password" size="10" />
        <asp:LinkButton Text="login" CssClass="submit"  runat="server" ID="lbLogin" OnClick="btnLogin_OnClick" />
</asp:Panel>

By wrapping the textboxes in a panel and setting the DefaultButton of the Panel to your LinkButton, any Enter in the text box inside the panel will cause the LinkButton Click to happen.

like image 194
Mrchief Avatar answered Oct 18 '22 03:10

Mrchief