<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio 7.0" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<SCRIPT language="JavaScript">   
function enterkey() 
{
if(event.keyCode==13)
{
WebForm1.Button1.click();
}

function movefocus(tbName)    
{    
if(event.keyCode==13)   
{
tbName.focus();
        
}      
}    
</SCRIPT>
<script language="C#" runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
TextBox1.Attributes["onkeydown"] = "javascript:movefocus(WebForm1.TextBox2)";
TextBox2.Attributes["onkeydown"] = "javascript:movefocus(WebForm1.TextBox3)";
TextBox3.Attributes["onkeydown"] = "javascript:movefocus(WebForm1.TextBox4)";
TextBox4.Attributes["onkeydown"] = "javascript:movefocus(WebForm1.Button1);enterkey()";
//Button1.Attributes["onkeydown"] = "javascript:enterkey()";
}

private void Button1_Click(object sender, System.EventArgs e)
{
Label5.Text = "演示过程结束.<br>由于时间问题,没有做到更好,有兴趣的朋友一起共同搞定啊,别忘记共享给大家";
}

override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{    
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load); }

</script>
</HEAD>
<body MS_POSITIONING="GridLayout" onkeydown="if(event.keyCode==13) return false;" onload="WebForm1.Button1.focus();WebForm1.TextBox1.focus()">
<form id="WebForm1" method="post" runat="server">
<asp:textbox id="TextBox1" style="Z-INDEX: 101; LEFT: 11px; POSITION: absolute; TOP: 29px" runat="server"
Width="94px"></asp:textbox>
<br>
<asp:textbox id="TextBox2" style="Z-INDEX: 102; LEFT: 9px; POSITION: absolute; TOP: 70px" runat="server"
Width="93px"></asp:textbox>
<br>
<asp:textbox id="TextBox3" style="Z-INDEX: 103; LEFT: 8px; POSITION: absolute; TOP: 112px" runat="server"
Width="91px"></asp:textbox>
<br>
<asp:textbox id="TextBox4" style="Z-INDEX: 104; LEFT: 6px; POSITION: absolute; TOP: 150px" runat="server"
Width="91px"></asp:textbox>
<br>
<asp:button id="Button1" style="Z-INDEX: 105; LEFT: 15px; POSITION: absolute; TOP: 195px" runat="server"
Text="Button1"></asp:button>
<br>
<asp:label id="Label1" style="Z-INDEX: 106; LEFT: 115px; POSITION: absolute; TOP: 32px" runat="server">TextBox1</asp:label>
<asp:Label id="Label2" style="Z-INDEX: 107; LEFT: 109px; POSITION: absolute; TOP: 73px" runat="server">TextBox2</asp:Label>
<asp:Label id="Label3" style="Z-INDEX: 108; LEFT: 106px; POSITION: absolute; TOP: 117px" runat="server">TextBox3</asp:Label>
<asp:Label id="Label4" style="Z-INDEX: 109; LEFT: 107px; POSITION: absolute; TOP: 155px" runat="server">TextBox4</asp:Label>
<asp:Label id="Label5" style="Z-INDEX: 110; LEFT: 16px; POSITION: absolute; TOP: 240px" runat="server"
ForeColor="Red"></asp:Label>
<asp:Label id="Label6" style="Z-INDEX: 111; LEFT: 190px; POSITION: absolute; TOP: 48px" runat="server"
Width="512px">这是一个比较完美的解决方案<br>按回车键光标自动移动到下一个TextBox,最后执行Button的OnClick事件<br>重要的是利用JavaScript<br><br>缺点有2个:<br>Page_load时,光标不能自动定位在TextBox1<br>当光标定位到Button1时,需要再按一次回车键才能触发Button1_OnClick事件</asp:Label></form>
</body>
</HTML>