给出简单代码说明:
1.用户控件(mycontrol.ascx):
<asp:ImageButton ID="mybtn" runat="server" OnClientClick="javascript:announceTime();return false;" />2.主页(Home.aspx)动态加载用户控件:
'声明一个用户控件对象
dim _mycontrol as UserControls_mycontrol   Private Sub UserControlLoad()
   ....   '载入调单用户控件
    Me.Panel1.Controls.Clear()
    Me._mycontrol = Me.LoadControl("~/UserControls/mycontrol.ascx")
    Me._mycontrol.ID = "_mycontrol1"
    Me.Panel1.Controls.Add(Me._mycontrol)
   End Sub'页面加载事件
 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    ...
    If Me.IsPostBack = True Then
         If ViewState("usercontrol")=1 Then
          .....
           Me.UserControlLoad()
          End if
    End if  End Sub'有一按钮触发动态加载用户控件
 Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) 
    ..... 
   If ViewState("usercontrol")  Is Nothing Then
            ViewState("usercontrol") = 1
           Me.UserControlLoad()
      End if
  End Sub顺便说明一下,以上动态加载用户控件的方法参考了网上一些资料,测试过可以正常使用,但是执行用户控件上面的客户脚本就发生上述问题,各位帮看看了。感觉是页面回传后没执行客户脚本这个执行过程是怎样的,搞不清楚啊,晕了。~~

解决方案 »

  1.   

    你是如何加载控件button的
    如果是html的话
    <input id="button" name="button" type="button" onclick="事件">
    如果是cs中定义
    Button bt=new Button();
    bt.ID="mybtn";
    bt.Attributes.Add("onclick","事件");
      

  2.   

    回火鸟:
    关于加载控件button,我的处理方法是:
    1.用户控件(mycontrol.ascx):
    <asp:ImageButton ID="mybtn" runat="server" OnClientClick="javascript:announceTime();return false;" />
    上面用的是服务器控件,html控件的方法我也试过了,不行。
      

  3.   

    看看生成的html代码是怎么样的,onclick事件中有没有你写的JS!!!