By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,947 Members | 1,594 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,947 IT Pros & Developers. It's quick & easy.

Submitting form by pressing the "ENTER" key

P: 4
Submitting Form by pressing the "ENTER" key
--------------------------------------------------------------------------------

Hi:

I have a search form in my application which has 4 dropdown list controls, one text box, one "GO" button, one "reset" button. When the "GO" button is clicked the form gets submitted and the results page is displayed. When I press the "enter" key nothing happens. I want to submit the form by pressing the "enter" key also. I have placed <input type="text" style="display:none"> after the <form> tag in the HTML section. Now if my cursor is in the text box only then the "enter" key press works. But in our case the text box is for "keyword" or "phrase". Most of the times the user doesn't use it, so the cursor is rarely there. We don't have ASP.NET 2.0, so I can't use the defaulltbutton property. Can anyone give me any suggestions? Thanks in advance.

Roxana
Oct 3 '06 #1
Share this Question
Share on Google+
4 Replies


P: 29
As per my understanding.
Go to properties of that button, selete the tab index and set it.
TabIndex is something which is selection order of controls .
so go to all the controls, like for example
set textbox tab to 1
set button tab to 2
so immediately after text box it sill select the button

U can also search in the web about the above.

I hope it helps.
Oct 3 '06 #2

P: 4
Hi:

Thanks for your prompt reply. I tried that but did not work. Isn't tab index for the tab key? I want to use the "enter" key. Thanks again.

Roxana

As per my understanding.
Go to properties of that button, selete the tab index and set it.
TabIndex is something which is selection order of controls .
so go to all the controls, like for example
set textbox tab to 1
set button tab to 2
so immediately after text box it sill select the button

U can also search in the web about the above.

I hope it helps.
Oct 4 '06 #3

bplacker
100+
P: 121
So from the text box, you want to be able to hit 'enter' and perform some action, correct? If this is the case.. you need to have a procedure which catches the key_down even for your text box.

the procedure will have 2 parameters passed in, one of which is the key down event (ByVal e As System.Windows.Forms.KeyEventArgs). to catch if the 'enter' key is pressed, do

if(e.keycode = keys.enter) then
'do some action
end if
Oct 4 '06 #4

P: 4
Hi:

Thanks for your reply but I have just solved my problem by some other way. Actually my problem was to make the "enter" key work when the cursor is not in the textbox. When the cursor is in the textbox the "enter" key works. This was accomplished by putting an invisible textbox by inserting
<input type="text" style="DISPLAY:none"> in between the <form> and </form> tags. It was necessary because I have only one textbox. What I did today is added the following in between the <HEAD> and </HEAD>tags.

<script language="javascript">
<!--
function SetFocus()
{
document.Form1['txtTitle'].focus();
}
window.onload = SetFocus;
// -->
</script>

This sets the cursor in the textbox when the page loads. Then I inserted the property AutoPostBack="True" in all my 4 dropdownlist controls. Now whatever I do in the form the cursor goes right back to the textbox, and when I hit "enter" the form gets submitted. I am feeling so great today I felt like sharing this with everyone.


So from the text box, you want to be able to hit 'enter' and perform some action, correct? If this is the case.. you need to have a procedure which catches the key_down even for your text box.

the procedure will have 2 parameters passed in, one of which is the key down event (ByVal e As System.Windows.Forms.KeyEventArgs). to catch if the 'enter' key is pressed, do

if(e.keycode = keys.enter) then
'do some action
end if
Oct 4 '06 #5

Post your reply

Sign in to post your reply or Sign up for a free account.