Asp. NET so that the same page different text box carriage return response to different events

Source: Internet
Author: User
Tags mail
asp.net| text Box | response | page
In ASP.net, if you have more than one text box on the same page, pressing the "enter" button in each text box will respond by default to the Click event of the first button and how you can press ENTER without causing an unexpected response or how to hit the ENTER key in different places to get a different response. This problem has plagued me for a long time, and so far has not been fully resolved, first of all, to share the current discussion, with a view to a start.
One, press ENTER at any place on the page does not trigger a response
If the entire page does not need to set carriage return submission, you want to press ENTER anywhere on the page does not trigger a response, you can turn the full page of the return to the tab, the method is in the file head plus the following code:

<script language= "javascript" event= "onkeydown" for= "Document" >

if (event.keycode==13)

event.keycode=9;

</script>




Second, in different places press ENTER to get a different response
If you have more than one text box (textbox) on the same page, each text box corresponds to a different submit button (a button), as in the following "login" pages, there are "Enter the mailbox Number" and "Enter account" two text boxes and "Enter the mailbox", "Enter the Community" two buttons.



The effect you want to achieve is:
1. Enter the mailbox number after entering, in response to the "Enter Mailbox" button event, for simplicity, the "Enter the Mailbox" button will appear in the "Message display" text box "mailbox: * * *" (which * * * for the input of the mailbox number), as shown in the following figure:



2. Enter the account number after entering, in response to the "Enter the Community" button event, for simplicity, the "Enter the Community" button will be in the "Information display" text box display "Community: * * *" (which * * * for the input of the Community account), as shown in the following figure:



The implementation steps are as follows:
1. Create pages and code files (this step is not described in detail)
2. Add a return response to the form by shielding the page
The code for KeyDown () is as follows:
function KeyDown () {}
3. Add the text box "Enter mailbox Number" and let it respond to the "Enter Mailbox" button event
The Mail () code is as follows:
function mail ()
{
if (event.keycode==13)
{
Document.all.MAIL.click ();
Alert (' Mail ');
}
}
4. Add the text box "Enter account" and let it respond to the "Enter Community" button event
The BBS () code is as follows:
Function BBS ()
{
if (event.keycode==13)
{
Document.all.BBS.click ();
Alert (' BBS ');
}
}




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.