how to show result by pressing Enter Key in a textbox
-
Hi.. i hav a problem in asp.net,i hav a search.aspx page which hav a textbox for keywords and a dropdownList for selection of category..and a Button for doing search..when i enter keyword in textbox and select category after then pressing Enter i dont get result..i hav to explicitly click on search Button to show result..so please tell me how to show result by pressing Enter as well aas by clicking on Button..
-
Hi.. i hav a problem in asp.net,i hav a search.aspx page which hav a textbox for keywords and a dropdownList for selection of category..and a Button for doing search..when i enter keyword in textbox and select category after then pressing Enter i dont get result..i hav to explicitly click on search Button to show result..so please tell me how to show result by pressing Enter as well aas by clicking on Button..
-
Here's an easy way to do it: //Allow hitting enter in textbox to submit form Page.RegisterHiddenField("__EVENTTARGET", "YOUR BUTTON NAME"); I hope that helps. Scott STocker
If you have only one button in your form, then that button is automatically assumed as default (submit type). So no need for tweaking around with EVENTTARGET hiddenfield. If you have more than one buttons, then Stockers' advice works fine for overriding the default behaviour. However I feel your problem here is not the texbox but the combobox. Hitting Enter key from textbox will work with above two methods. But hitting Enter when focus is on combobox, does not trigger the button. Try using some javascript for this purpose: First insert a dummy LinkButton in your form (this will include the hooker function __doPostBack into you HTML code). You can keep the text property of Link button as nothing. Thus the link button will not be visible on the page. Now add this script to your section.
function processKeyEvent(){ if(window.event.keyCode==13) __doPostBack('Button2',''); }
Note that in the abv snippet, you are programatically calling the postback feature of ASP.NET __doPostBack('Button2',''); tells the browser to postback the page assuming that Button2 was clicked. Finally, in the onkeypress event of tag, add this:onkeypress="return processKeyEvent();"
hth -geo Nothing is impossible!