In the text box input box, how does one press the Enter key and the cursor automatically jumps to the next text box input box or execute a button to submit?

Source: Internet
Author: User
These two problems are essentially the same. They are generally solved using the client script, for example.
C # <% @ Page Language = " C # "   %>
< Script runat = " Server " >
  Protected   Void Button_click ( Object Sender, eventargs E)
{
Lable1.text="You have clicked:"+(Button) sender). text;
}

Protected   Void Page_load ( Object Sender, eventargs E)
{
Int Textboxnum = 4 ;
For ( Int I = 1 ; I <= Textboxnum; I ++ )
{
If (I ! = Textboxnum)
{
(Textbox) form1.findcontrol ( " Textbox " + I. tostring (). Attributes. Add ( " Onkeydown " , " Tabnext (event, '0 ',' " + (Textbox) form1.findcontrol ( " Textbox + (1 + I). tostring (). clientid +' " ) " );
}
Else
{
(Textbox) form1.findcontrol ("Textbox"+I. tostring (). Attributes. Add ("Onkeydown","Tabnext (event ,'"+Button2.clientid+'",)");
}
}
}
</ Script >

The page contains a form1 form, four Textbox, A button2 button, and a label1

Add the following Javascript script to the page: < Script Language = "JavaScript" Type = "Text/plain csript" >
Function Tabnext (E, S1, S2)
{
If (Window. Event) // IE
{
Keynum=E. keycode
}
Else   If (E. Which) // Netscape, Firefox, opera
{
Keynum=E. Which
}

If (Keynum = 13 )
{
If (S1 = " 0 " )
{
Document. getelementbyid (S2). Focus ()
}
Else
{
Docuemnt. getelementbyid (S1). Click ()
}

If (Window. Event)
{
E. returnvalue=False;
E. cancelbubble=True;
}
Else   If (E. Which)
{
E. rreventdefault ()
}
}
}
</ Script >

Remember to bind the onclick event of onclick of button2 to button_click.

The above content is taken from Mencius's ASP. NET 2.0 application development technology

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.