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