试试看
<asp:textbox id="mytext1"....>
<asp:button id="mybutton1" ..>
.cs代码
mybutton1.Attributes["onclick"]="javascript:handler()";
mytext1.Attributes["onrowenter"]=mybutton1.Attributes["onclick"];
我也没有测试过,你试试看。

解决方案 »

  1.   

    不好用啊。"javascript:handler()  "是什么啊?
      

  2.   

    你可以设置TextBOx的属性为autopostback,然后在他的TextChanged事件中写查询事件就可以了,因为当你的text内容变换,而按enter键的时候,总是触发第一个按钮的Button_Click事件。所以你的查询按钮必须是第一个按钮才行。
      

  3.   

    感谢您使用微软产品。
     
    这个问题是和IE的特性相关的。在IE浏览器中,如果TextBox中有光标,也就是它获得了焦点, 这个时候我们按下回车,IE会产生两种不同的Post操作。如果页面中同一个Form中只包含一个TextBox, 则IE Post的数据中不会包含任何的和Button相关的信息。自然,在ASP.NET中,也就不会在Server端触发Button 的Click事件。如果页面中包含多于一个TextBox, 则IE会在浏览器端自动click同一个Form中的第一个Button, 同时,post到Server端的数据中也包含该button的相关信息,ASP.NET会在Server端自动调用该ServerControl中IPostBackEventHandler接口中的方法。这样,建议您采用下面方法达到您的目的:1. 在您的Form中,加入一个隐藏的TextBox.注意:不要再Properties Browser中把Visible设置为false, 在声明TextBox的地方,加入 style="visibility:hidden;...".2. 您可以使用TextBox德Change事件,不过这样有限制。3。加入下面的代码:<script runat=server language=c#>
    public void button1_click (Object s, EventArgs e)  {
                Response.Write("click");
    }function clickButton() {
                if (event.keyCode == 13)  {
                            document.form.button1.click();
                            return false;
                }
    }
    </script><form runat=server id=form >
                <input type=text id="textbox1" runat=server  onkeypress="return(clickButton());">
                <input type=submit id="button1" runat=server  OnServerClick=button1_click>
    </form>希望上面的信息对您有所帮助。 
     
    -微软全球技术中心  -zgh
     
    本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
    为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。