Tutorial :Choose Enter Rather than Pressing Ok button



Question:

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.


Solution:1

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


Solution:2

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.


Solution:3

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


Solution:4

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


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »