绑定用户控件button事件

来源:互联网 发布:软件企业评估减税 编辑:程序博客网 时间:2024/06/05 03:36

大家都知道怎么绑定button事件,我们做网站时发现一个问题,当页面用了用户控件以后,在页面上再绑定button时有些迷惑

是在页面里写,还是在用户控件里写?

我通过实际操作发现是在用户控件里写

但是var button = document.getElementById("Search1_ImageButton1");  
这句话,获取的id是通过在页面运行时查看源文件时找到的

只有这样代码才能起作用。

 

<script type="text/javascript">
function   noEnter(){
 var button = document.getElementById("Search1_ImageButton1");  
        if(window.event.keyCode==13)
            {                    
              button.click();        
              event.returnValue = false;                   
            }
  }  
  </script>

 

<asp:TextBox ID="TextBox1" runat="server" onkeypress="noEnter();" ></asp:TextBox>

 

 <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/top/搜索.gif" OnClick="ImageButton1_Click1" CausesValidation="False" />

 

 

原创粉丝点击