要实现的要求,
第一步,TextBox内输入文本后,回车,可以执行 Button1的Click事件
第二步,Button1的Click事件完成后,Web的焦点反馈TextBox目前,第一步已经实现
实现原理,TextBox内回车的时候,焦点设定为Button1
问题,第二步怎么实现
不知道,请各位帮忙,感谢-------------------------第一步实现的具体方法1:加javascript语句如下
    <script type ="text/javascript" >
        function SetKeyFocus(str1)
        {
            if(event.keyCode==13)
                {
                    var a;
                    a=str1;
                    eval("window.document.form1."+a+".focus();");
                }
        }
    </script>
2:TextBox控件事件增加如下    <asp:TextBox ID="tbAppName" runat="server" onkeydown="SetKeyFocus('btnAppAdd');" ></asp:TextBox>

解决方案 »

  1.   

    Button1是个服务器控件吗?
    如果是,那么在
    Button1的Click事件 里面,
    tbAppName.Focus();即可将光标移动到tbAppName上如果是html button 那么onclick时间里面 "document.getElementById('tbAppName').focus()"
    即可
      

  2.   

    document.getElementById('tbAppName').focus()
      

  3.   

    本帖最后由 net_lover 于 2011-04-29 13:47:29 编辑
      

  4.   

    补充一下,Button1是服务器控件。
    但是页面使用了Ajax,Button点击后,貌似不发生页面回传,所以,在Click的C#里面写,好像没有用。
      

  5.   

    Ajax不是更简单吗?
    document.getElementById("<%=服务器控件.ClientID%>").focus()
      

  6.   

    这句话在哪里写呢?我是直接用的Ajax控件,所以原理不是很懂啊。
    谢谢
      

  7.   

    本帖最后由 net_lover 于 2011-04-29 14:39:15 编辑
      

  8.   

    我是直接把控件放到ASP.NET的UpdatePanel里面,实现Ajax无刷新功能的。
    所以,没有专门的Ajax代码...
      

  9.   

    直接拷贝执行这个例子
    你就明白了
    <%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">  protected void Button1_Click(object sender, EventArgs e)
      {
        form1.DefaultFocus = "TextBox2";
      }
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
      <title></title>
      <script>alert("这个只弹出一次,如果弹出多次,页面就是刷新了。")</script>
    </head>
    <body>
      <form id="form1" runat="server">
      <asp:ScriptManager ID="ScriptManager1" runat="server">
      </asp:ScriptManager>
      <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
        TextBox1:<asp:TextBox ID="TextBox1" runat="server">
        </asp:TextBox>
        <br />
        TextBox2:<asp:TextBox ID="TextBox2" runat="server">
        </asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="点击提交,将焦点定位在 TextBox2 上" OnClick="Button1_Click"
          Style="height: 21px" />
        </ContentTemplate>
      </asp:UpdatePanel>
      </form>
    </body>
    </html>
      

  10.   

    另外,你的问题描述里面根本就没有提 ajax的东西,
    要想快点解决你的问题吗》?请把问题说清楚
      

  11.   

    Dear net_lover,
    非常感谢你的帮助,但是,你给的代码,我测试,没有运行成功。我安装的是
    ASP.NET 2.0 AJAX Extensions v1.0.61025,不是道是不是这个版本有问
    题,请帮忙再看看,非常感谢。
      

  12.   

    那就用javascript的focus啊
    document.getElementById("").focus();
      

  13.   

    document.getElementById("<%=服务器控件.ClientID%>").focus()这个就可以。
      

  14.   

     <script type ="text/javascript" >
      function SetKeyFocus(str1)
      {
      if(event.keyCode==13)
      {
      var a;
      a=str1;
      eval("window.document.form1."+a+".focus();");
      }
      }
      document.getElementById("文本框ID").focus()
      </script>