web form submit behavior in ASP.NET RESOLVED
How can I stop or catch or detect when a user hits enter in my web form. I have all of the database input code inside a submit button and if the user hits enter the form submits, is cleared and missed all of my code. Also the user hates the form submit on enter behavior.
Is there some way to detect an event argument or something in the page unload event (or some event) to check if it was triggered by enter and if so then go back? What is the asp.net code equivalent of the user hitting the back key?
I am hoping I do not need a client side javascript here because it seems like a lot of work... and I don't know javascript.
Thanks.
Re: web form submit behavior in ASP.NET RESOLVED
I have a text box and a submit button. How do I capture the user hitting enter while the text box has focus and calling the submit button's click event?
I don't want to put the button's click event code in the Page_Load event as it causes other problems. Alternatively, I could put the button's click event code in the Page_Load event if I was able to detect which object/event caused the page to be submitted to the server.
Re: web form submit behavior in ASP.NET RESOLVED
Robertx-
you should scroll up and review nemaroller's advice. it worked perfectly for me. unless I misunderstand your question, that should do the trick.
Re: web form submit behavior in ASP.NET RESOLVED
Thanks, soskinny. I used an adaptation of this code from another thread:
VB Code:
Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
txtSearch.Attributes.Add("onkeydown", String.Format("if(window.event.keyCode == 13) {{{0}.focus();}}", cmdSearch.ClientID))
End Sub
and it did exactly what I wanted it to do. ie.calls the cmdSearch button click event when the user hits enter when txtSearch has focus.