Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to detect when the ENTER key is pressed in an ASP.net page

Posted on 2005-04-12
2
Medium Priority
?
578 Views
Last Modified: 2011-04-14
Hi,
 
 I have a page where I need to detect when the ENTER key is pressed in a textbox web control

 How can I do this?

 Thanks in advance
0
Comment
Question by:negreteo
  • 2
2 Comments
 
LVL 14

Accepted Solution

by:
puranik_p earned 2000 total points
ID: 13769233
You need to use javascript for that.
here's a function which submits the form on pressing Enter key in a textbox.


function checkEnter(e){ //e is event object passed from function invocation
var characterCode literal character code will be stored in this variable

if(e && e.which){ //if which property of event object is supported (NN4)
e = e
characterCode = e.which //character code is contained in NN4's which property
}
else{
e = event
characterCode = e.keyCode //character code is contained in IE's keyCode property
}

if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
document.forms[0].submit() //submit the form
return false
}
else{
return true
}

}


<input type="text" onKeyPress="checkEnter(event)">
<!-- don't forget to pass the event to the function for NN4 -->
0
 
LVL 14

Expert Comment

by:puranik_p
ID: 13787996
glad to help out. :o)

Pura
0

Featured Post

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question