how can focus a textbox into a search button when user hit enter key in text box

Posted by Bhuwan87rawat under ASP.NET on 8/30/2012 | Points: 10 | Views : 1686 | Status : [Member] | Replies : 4
Sir
In my application a take a textbox and also a serch button when i type some thing in textbox then hit the enter key then the textbox focus on
the search button...
how can possible in asp.net

Regard
Bhuwan




Responses

Posted by: Vuyiswamb on: 8/30/2012 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
In your Form Tag there is a property called DefaultButton and just assign it to the name of the Button

<form id="form1" defaultbutton="btnLogin" runat="server">


Thank you for posting at Dotnetfunda
[Administrator]

Bhuwan87rawat, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jasminpatel on: 8/30/2012 [Member] Starter | Points: 25

Up
0
Down
if you are using Window Application then set Form Property AcceptButton='Your_Search_Button_ID
Like AcceptButton=btn_search

Thank you.

jasmin patel

Bhuwan87rawat, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 8/30/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Try this,
Add this code on ur page load.
u can also refer this url
http://www.dotnetfunda.com/codes/code3088-focus-a-textbox-into-a-button-when-user-hit-enter-key-in-text-box.aspx

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
TextBox1.Attributes.Add("onkeypress", "return clickButton(event,'" + Button1.ClientID + "')");
TextBox2.Attributes.Add("onkeypress", "return clickButton(event,'" + Button2.ClientID + "')");
}
}

Add this javascript on ur ASPX page.
 

<script type="text/javascript" language="javascript">
function clickButton(e, buttonid) {
var evt = e ? e : window.event;
var bt = document.getElementById(buttonid);
if (bt) {
if (evt.keyCode == 13) {
bt.click();
return false;
}
}
}
</script>


Bhuwan87rawat, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 8/30/2012 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
@Jasminpatel the Question was specifically for web not Desktop app

Thank you for posting at Dotnetfunda
[Administrator]

Bhuwan87rawat, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response