1

I have asp.net Login control, example

<asp:Login ID="Login" onauthenticate="LoginAuthenticateEvent" runat="server"/>

have *.cs function like

protected void LoginAuthenticateEvent(object sender, AuthenticateEventArgs e)
{
    //..
}

But it launch Authenticate only if pressing login Button, not by 'Enter' in textboxes.

So I decided to set this event to javascript 'onkeypress' event, and want it to check if keycode is 13(Enter) - and launch LoginAuthenticateEvent. But there is problem - to call C# function from JS function should be static, but in my case it is 'protected void'

In JS(jQuery) code I get necessary element like this:

var tboxUserName = $("input[name*='UserName']");

I understand that there should be somethin like

tboxUserName.attr("onkeypress","....");

But how to hang there key check and make it such as onauthenticate="LoginAuthenticateEvent"?

upd.: Tried find control on Server side, and add TextChanged event there

TextBox tb = (TextBox)Login.FindControl("UserName");
tb.TextChanged += tbox_TextChanged;

But 'TextChanged' event fires only on focus change(when click other textbox or button) - but I need to check every keypress. So question is still opened.

Gennady G
  • 996
  • 2
  • 11
  • 28

1 Answers1

0

Yes, solution from @Dave Becker is working. In my case my Login control is branded and there was not Button, but ImageButton. In this the code looks like this:

<asp:Panel ID="panelLogin" runat="server" DefaultButton="Login$LoginImageButton"> 
<asp:Login ID="Login" onauthenticate="LoginAuthenticateEvent" runat="server">
</asp:Login>
</asp:Panel>
Gennady G
  • 996
  • 2
  • 11
  • 28