tags:

views:

98

answers:

4

I have many fields in the page and the last field is a dropdown with list of values. When I select an item in a dropdown and press Enter, it doesn't do the "Ok". Instead I have to manually click on Ok to Submit. How can I do by pressing Enter on my Keyboard rather than Clicking on "Ok" button after selecting the value from dropdown list. I have set the SubmitBehavior to true.

+3  A: 

Try the solution here: ASP.NET 2.0 - Enter Key - Default Submit Button.

Chris Thompson
You answer talks about Win forms, the OP is asking about Web forms. I won't vote, though.
Moayad Mardini
Thanks, I misread that site, the concept is the same, I'll find a new link
Chris Thompson
Good link. +1..
Moayad Mardini
Made up for my bone head :) good edit, thanks!
Chris Thompson
You're more than welcome.
Moayad Mardini
great link, thanks!
adrianos
+1  A: 

Assuming you're talking about a web form:

I'm no ASP.NET guru, but the default behavior of an HTML form is to submit in this case. Common causes for this are the HTML form fields not being contained within the form element, or the submit button having a nonstandard javascript function fire instead of submitting proper.

I realize that's not an answer, but I hope it might help.

Adam Bard
+1  A: 

using jquery you can do something like this

$("#fieldName").keypress(function(event)  
    {  
        if (event.keyCode == 13)  
        {  
            return true;  
        }  
        else  
        {  
            return false;  
        }  
    });

See more here: http://docs.jquery.com/Events/keypress

Andrew Siemer
A: 

Try setting Page.Form.DefaultButton = OkButton; in your code-behind.

Greg