?
Solved

How to let 'Enter' key stroke to do the same thing as hit 'Submit' button in ASP.NET 2.0 application?

Posted on 2007-11-27
7
Medium Priority
?
731 Views
Last Modified: 2013-11-26
In login page of clasic asp application, if user enters password in password field and hit the 'Enter' key, the page is submitted without need to click the 'Submit' button.

How to do the same thing in ASP.NET 2.0 application? I think it should be easy but I cannot find the solution.

Thanks for your help.
0
Comment
Question by:zhuansun
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 7

Expert Comment

by:Maverick_Cool
ID: 20358123
This can be achieved by attaching a *Event 'onKeyDown' , in the event handler it key enter invoke form.submit.


*Using javascript
0
 
LVL 1

Expert Comment

by:_Zenix_
ID: 20358138
Access keys

Attribute definitions

accesskey = character [CN]
    This attribute assigns an access key to an element. An access key is a single character from the document character set. Note. Authors should consider the input method of the expected reader when specifying an accesskey.

Pressing an access key assigned to an element gives focus to the element. The action that occurs when an element receives focus depends on the element. For example, when a user activates a link defined by the A element, the user agent generally follows the link. When a user activates a radio button, the user agent changes the value of the radio button. When the user activates a text field, it allows input, etc.

The following elements support the accesskey attribute: A, AREA, BUTTON, INPUT, LABEL, and LEGEND, and TEXTAREA.

This example assigns the access key "U" to a label associated with an INPUT control. Typing the access key gives focus to the label which in turn gives it to the associated control. The user may then enter text into the INPUT area.

<FORM action="..." method="post">
<P>
<LABEL for="fuser" accesskey="U">
User Name
</LABEL>
<INPUT type="text" name="user" id="fuser">
</P>
</FORM>

In this example, we assign an access key to a link defined by the A element. Typing this access key takes the user to another document, in this case, a table of contents.

<P><A accesskey="C"
      rel="contents"
      href="http://someplace.com/specification/contents.html">
    Table of Contents</A>

The invocation of access keys depends on the underlying system. For instance, on machines running MS Windows, one generally has to press the "alt" key in addition to the access key. On Apple systems, one generally has to press the "cmd" key in addition to the access key.

The rendering of access keys depends on the user agent. We recommend that authors include the access key in label text or wherever the access key is to apply. User agents should render the value of an access key in such a way as to emphasize its role and to distinguish it from other characters (e.g., by underlining it).
0
 
LVL 16

Expert Comment

by:SQL_SERVER_DBA
ID: 20358143
Page.RegisterHiddenField( "__EVENTTARGET", myButton.ClientID );
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 1

Expert Comment

by:_Zenix_
ID: 20358194
have a look at this:

<form name="myform" action="handleaction.asp">
<input type="submit" value="Submit" name="B1" onkeydown="javascript: submitform()">
</form>
<SCRIPT language="JavaScript">
function submitform()
{
  document.myform.submit();
}
</SCRIPT>
0
 
LVL 10

Expert Comment

by:Oliver Amaya
ID: 20358237
Hi, in asp.net you can do the same thing without adding any code, as long as you have only one submit button in your page, when Enter is hit the button's onclick event will be called.
0
 
LVL 37

Accepted Solution

by:
samtran0331 earned 100 total points
ID: 20358353
>>How to do the same thing in ASP.NET 2.0 application?

In ASP.Net, you can set which button is triggered when a user clicks "Enter" using the defaultbutton attribute on the form tag

<form runat="server"...defaultbutton="buttonname"...>

panel controls also have a defaultbutton attribute...
so the form can have a default button, and you can have multiple panels, each with different default buttons, and depending which panel is in "focus", a different defaultbutton will fire when clicking "enter"
0
 

Author Closing Comment

by:zhuansun
ID: 31411196
Your solution is the best for my ASP.NET 2.0 application.
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

770 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