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.
当有人在tbUsername或tbPassword上输入时,我想调用“btnLogin_OnClick函数”。
How do I do this?
我该怎么做呢?
2 个解决方案
#1
13
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.
通过将文本框包装在面板中并将Panel的DefaultButton设置为LinkButton,面板内的文本框中的任何Enter都将导致LinkButton Click发生。
#2
0
// Code-behind
protected void btnLogin_OnClick(object sender, EventArgs e)
{
if (Page.IsValid)
{
// process your form
}
}
#1
13
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.
通过将文本框包装在面板中并将Panel的DefaultButton设置为LinkButton,面板内的文本框中的任何Enter都将导致LinkButton Click发生。
#2
0
// Code-behind
protected void btnLogin_OnClick(object sender, EventArgs e)
{
if (Page.IsValid)
{
// process your form
}
}