How does asp.net respond to the carriage return event during page loading?
Protected void Page_Load (object sender, EventArgs e)
{
This. Page. SetFocus (TextBox1); // sets the focus.
}
Protected void Page_Load (object sender, EventArgs e)
{
// Press enter and then submit Button1
This. page. registerClientScriptBlock ("_ autoPostBack", "<script type =" text/javascript "> function document. onkeydown () {if (event. keyCode = 13) {document. getElementById ('"+ Button1.ClientID + "'). click () ;}</script> ");
}
Asp.net (c #) how to add focus to the text control during page loading
This. Page. RegisterStartupScript ("", "<script> document.forms(02.16.txt Family. focus (); document.forms(02.16.txt Family. select (); </script> ");
How to set the default press enter button on the asp.net page
Logonidtextbox. attributes ["onkeydown"] = "if (event. keycode = 13) {document. all. logonpasswordtextbox. focus (); return false ;}";
Logonpasswordtextbox. attributes ["onkeydown"] = "if (event. keycode = 13) {document. all. buttonlogon. click (); return false ;}";
Or Add code to the chenage event in the text box.
Turn the cars on the page into tabs.
<Script language = "javascript" event = "onkeydown" for = "document">
If (event. keyCode = 13 & event. srcElement. type! = 'Button '& event. srcElement. type! = 'Submit '& event. srcElement. type! = 'Reset' & event. srcElement. type! = '')
Event. keyCode = 9;
</Script>
In ASP.. NET. If multiple text boxes exist on the same page, press "enter" in each text box to return the Click event of the first Button by default, how can I press the Enter key without causing unexpected response or how to press the Enter key in different places to get different responses?
2. Press enter in different places to get different responses
Www.2cto.com if there are multiple text boxes on the same page, each text box corresponds to a different Button, such as the following "login" page, there are two buttons: "Enter mailbox number" and "enter account", "Enter mailbox", and "Enter community.
The implementation steps are as follows:
1. Create a page and code file (this step is not described in detail)
2. Add onkeydown = "keydown ()" to form to block the carriage return response of the page.
The code for keydown () is as follows:
Function keydown (){}
3. Add onkeydown = "mail ();" to the text box for "Enter mailbox number" to 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 onkeydown = "bbs ();" to the text box of "enter account" to 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 ');
}
}
Press enter to execute the specified button event on the page
ASP. NET allows different text boxes on the same page to respond to different submitted button events when you press Enter.
1. Step 1: create the following javascript:
<Script language = "javascript">
<! --
Function KeyDown (){
If (event. keyCode = 13 ){
// In the form page, press enter to not trigger the event
Return false;
}
}
Function doButton (){
If (event. keyCode = 13 ){
// BtSubmit indicates the id of the corresponding submitted button.
Document. all. btSubmit. click ();
}
}
// -->
</Script>
2. Step 2: add the "onKeyDown" label to FORM, as shown below:
<Form id = "Form1" method = "post" runat = "server" onKeyDown = "return KeyDown ()">
</Form>
3. Step 3: add the "onKeyDown" label to the text box to press enter, as shown below:
<Asp: TextBox id = "TextBox1" runat = "server" onKeyDown = "doButton ()"> </asp: TextBox>
Here is the submit button:
<Asp: Button id = "btSubmit" runat = "server" Text = "Submit"> </asp: Button>
The above is for reference only.
Haha, it is feasible to perform the test on your own. You need to give the button a focus first.
This. textBox1.Attributes. add ("onkeypress", "if (event. keyCode = 13) {document. all. btnGOTO. focus (); document. all. btnGOTO. click (); return false ;}");
This. textBox1.Attributes. add ("onkeydown", "if (event. keyCode = 13) {document. all. btnGOTO. focus (); document. all. btnGOTO. click (); return false ;}");
There are multiple buttons on a page. Sometimes you want to press enter to directly click a button. The solution is as follows:
<Script language = "javascript">
Function document. onkeydown ()
{
Var e = event. srcElement;
If (event. keyCode = 13)
{
Document. getElementById ("id of the button to be clicked"). click ();
Return false;
}
}
</Script>
If there are multi-line text boxes on the page, press enter in the multi-line text box to implement line breaks instead of submitting the form for such modification.
If (e! = Document. getElementById ("multi-line text box id") & event. keyCode = 13)
1. No response is triggered when you press the Enter key anywhere on the page.
If you do not need to set a carriage return to submit the entire page, you can convert the carriage return to a Tab if you want to press the carriage return key wherever the page is, add the following code to the file header:
<Script language = "javascript" event = "onkeydown" for = "document">
If (event. keyCode = 13)
Event. keyCode = 9;
</Script>
From caoruyi15's column