Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 5th, 2004, 05:02 PM
Registered User
 
Join Date: Oct 2003
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?

KO
 
Old January 21st, 2004, 02:34 PM
Registered User
 
Join Date: Jan 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi:

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
 
Old August 17th, 2004, 09:57 AM
Registered User
 
Join Date: Aug 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.