How to create a form using LinkButton?

My usercontrol user has two text fields and a link button.

<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 presses enter tbUsername or tbPassword.

How to do it?

+6
source share
2 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 text fields in the panel and setting the DefaultButton panel to your LinkButton , any input in the text field inside the panel will call LinkButton Click to occur.

+13
source

// Code for

 protected void btnLogin_OnClick(object sender, EventArgs e) { if (Page.IsValid) { // process your form } } 
0
source

Source: https://habr.com/ru/post/896047/


All Articles