Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 5th, 2004, 05:02 PM
Registered User
Join Date: Oct 2003
Location: Manassas, VA, USA.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Enter Key event handler

I would like to be able to let the user hit the enter key to trigger the Submit button click event. I did a Google search on the subject, and I found a few examples, but I don't think I really understood them completely. It seems like a very basic and common part of most projects, so I know this should be an easy one for someone out there. As an example, let's say a textbox is called txtDocNum, and the Submit button is called, oddly enough, btnSubmit. What do I need to do?

  #2 (permalink)  
Old January 21st, 2004, 02:34 PM
Registered User
Join Date: Jan 2004
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts


I've been trying for days to solve this very issue. Then a colleague came over and handed me an article from the February 2004 issue of asp.netPRO, which addressed this whole issue. If you can't find it on the news stands, then try visiting their site: www.aspnetPRO.com. The article's called HIT ENTER AND POST BACK. My only remaining question is, does this work for asp:ImageButton?

Hope this helps!
Sled Dog
  #3 (permalink)  
Old August 17th, 2004, 09:57 AM
Registered User
Join Date: Aug 2004
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

Here are two things I have found useful one of which may solve your question the other is only helpful for the simple setting of a starting point within your page for the cursor. These are ASP.net specific and are in VB.net coding. I hope they help. I have tried to give some commenting for them and an example of where these bits of code are best placed.

This first portion shows where in your code you will need to place the function calls.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Me.SetFocus(Me.tbPass) 'Change the tbPass portion to any of the text boxes in your code to make the cursor start in that box

Page.RegisterHiddenField("__EVENTTARGET", "btnSubmit") 'This will setup an event trigger that waits for either enter to be pressed and then redirects it as if it were a mouse click to whichever button or link you specify in this case the btnSubmit

End Sub

This is the function portion of the SetFocus call, it could be placed in a header for use throughout a program or used in a specific page

Private Sub SetFocus(ByVal ctrl As System.Web.UI.Control)

Dim s As String = "<SCRIPT language='javascript'>document.getElementById('" & ctrl.ID & "').focus() </SCRIPT>"

RegisterStartupScript("focus", s)

End Sub

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Enter Key Event (Enter Key Only) Coby Excel VBA 0 February 6th, 2008 09:55 PM
enter key should execute button click event MunishBhatia ASP.NET 2.0 Professional 6 November 25th, 2007 10:59 PM
Capturing a "Enter" key event in C# windows applic bhavna VS.NET 2002/2003 1 March 15th, 2007 07:45 AM
enter key on textbox, performs button event code?? squeakstar Visual Basic 2005 Basics 4 June 22nd, 2006 05:13 AM

All times are GMT -4. The time now is 07:27 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.