Select Categories Below
Advertisement
Start Your Own Q&A Site
Create your own Q&A site easily, allowing you to quickly grow a new community around any subject matter or generate new organic traffic for your existing website.
Status: Closed Points: 50 Time: 03:26 - Dec 21, 2006
david
How do I make it so that if a user is pressing the enter key when typing in a textbox, the form will be automatically submitted?
Categories:
Add Categories
When adding more than one category, separate them with commas.
Date:: Dec 21, 2006
Time:: 03:54
Actually it would be great if it could be integrated with ASP.NET 2 somehow. I mean I want to "simulate" a button click and there might be several buttons on the page doing different stuff.
rcastagna
Time:: 09:27
David, Sometimes, this is the default behavior when the enter key is pressed...it depends on whether or not you a single "submit" button on a page (this includes usercontrols, third party controls, etc.). I think there are a couple of ways you could go about simulating this behavior - both of them being client-side, however. 1) Wire up a global javascript event that "traps" the keypress event for the enter key, or 2) Add a javascript function which will conditionally process the events regardless of which control initiated the submit, ie: <script type='text/javascript'> function pressedEnter(control) { // You would want to put a switch statement in here // to handle the control coming in. alert(control); } </script> <input type='text'> <input type='text''> <input type="submit" onsubmit='pressedEnter(this)'> Granted, it's not a server-side solution, but really, none of the events are truly server-side...they're just client-side events that initiate specific server-side routines based on the information contained in the __doPostBack javascript function.
multani.sarbjit
Date:: Dec 28, 2006
Time:: 00:54
Well David, Try this <form id="form1" defaultbutton="btnSubmit" defaultfocus="textbox1" runat="server"> This will set btnSubmit as default button of the form
Time:: 06:29
Thanks for your help guys. I ended up doing it this way serverside (ASP.NET 2 / C#): string loginFocusScript = "<script>var textBox = document.getElementById('" + this.Login.UsernameTextbox.ClientID + "');"; loginFocusScript += "if (textBox != null) {textBox.focus();}</script>"; this.Page.ClientScript.RegisterStartupScript(this.GetType(), "loginFocus", loginFocusScript); Not too happy with it, but it works.
Question Answered
This question has been closed, and points have been rewarded to the following experts:
You're welcome however to comment or give additional information or if you wish, you have the ability to write a Tutorial in the Tutorial Area.
Answer this Question
New User
Email:
Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address
Registered User
Username:
Password:
Forgot Your Password?
Enter your email address below and we will resend your login information to you.
Login Information Sent
Questions
whats the best food to eat during midnight?
How to identify the tiffany jewelry? www.tffanycheapmall.com.
Send an email alert to each user of the php application based on criteria
How I Increased My AdSense Earnings?
how to choose the lady dress ?
How can I fulfill the minimum requirement to make your computer support 3D?
You have 100 characters to use
Rank
Expert
Points
1.
10354
2.
6493
3.
5596
4.
4848
5.
3487
6.
2840
7.
2770
8.
2303
9.
1820
10.
917
Register today to share your knowledge with the community and be recognized and rewarded for your contributions.
Register Here
"Psst, Quomon is a great site. Pass it on." Tell a Friend | Link To Us | Save to Delicious | Digg it
Language Options
English:
Español:
Sponsors
Questions and Answers Software