下面的代码是两个TextBox,对应两个Button        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Button" />
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <asp:Button ID="Button2" runat="server" Text="Button" />我要问的是.比如我在TextBox1输入文字,那么我按回车键,对应"激活"的是Button1,如果我在TextBox2输入文字,按回车键,对应激活的是Button2
应该怎么编代码?谢谢

解决方案 »

  1.   

      <input type="password" name="password" onkeypress="if(event.keyCode==13){ event.returnValue = false;document.getElementById('ctl00$IndexContentPlaceHolder$btnLogin').click();}"
                                                                id="password" style="width: 148px;" tabindex="2" />
      

  2.   

    还是不行吧.
    我在后台代码这样:
    TextBox1.Attributes.Add("onkeypress", "if(event.keyCode==13){ event.returnValue = false;document.getElementById('ctl00_ContentPlaceHolder1_txtSearchKey').click();}");
      

  3.   

    上面复制错了.应该是
    TextBox1.Attributes.Add("onkeypress", "if(event.keyCode==13){ event.returnValue = false;document.getElementById('ctl00_ContentPlaceHolder1_TextBox1').click();}");
      

  4.   

    喔.明白了.呵呵.原来是getElementById 是Button的click
      

  5.   

    那不如隻用一個button
    根據TextBox1與TextBox2是否為空來執行相應語句
      

  6.   

    其实上面我举的例子是最简单的啦.在应该中不会是我举例的那样两个textbox,对应两个button像一个页面,左边是登陆框,中部是搜索新闻框,右边是其它搜索框,这样就肯定要用到1楼上面的办法了.