Submit Button event for EnterKey in Asp.Net

C

conckrish

Hi All,

I have two textboxes(Emailid,passwd) and a Button Submit in my
Webform.I have set focus to Email textbox by using JavaScript.Now how
to call the Submit button_click event when we hit Enter key from the
Key board?Can any one give me the Code samples for this problem?


Thanx,
Krish.
 
T

Teemu Keiski

Hi,

with ASP.NET v2.0

You could have

<body onkeypress="if(event.keyCode==13){postForTheButton}" >

<form id="form1" runat="server">
<div>
<asp:TextBox ID="emailid" runat="server" />
<asp:TextBox ID="passwd" TextMode="Password" runat="server" />
<asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" />
<script type="text/javascript" >
function postForTheButton()
{
<%=Page.ClientScript.GetPostBackEventReference(btnSubmit,"")%>
}
</script>
</div>
</form>

</body>

If you use v1.0, replace Page.ClientScript.GetPostBackEventReference with
Page.GetPostBackEventReference
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top