给出简单代码说明:
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.用户控件(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顺便说明一下,以上动态加载用户控件的方法参考了网上一些资料,测试过可以正常使用,但是执行用户控件上面的客户脚本就发生上述问题,各位帮看看了。感觉是页面回传后没执行客户脚本这个执行过程是怎样的,搞不清楚啊,晕了。~~
解决方案 »
- 页面分辨率问题
- 新手求救!不能新建一个ASP.ENT WEB应用程序
- 如何动态的显示服务器端的日期、时间及星期几(见详情)
- 如何选CheckBoxList中选中的值
- 关于ASP.net开发环境一个郁闷的问题
- 在.cs中写表单在.aspx中写js函数提交??????求助~~~~
- 怎样配置asp.net程序以最大权限(比如administrator)运行,而不是以 aspnet运行,是不是要修改web.config文件
- 奇怪的错误,各位大虾帮看一下!
- 紧急求助于:使用datagrid分页,若有模板列checkbox,怎样实现按一按钮能把所有分页中的checkbox都选中??
- 数据是父子类型的N级,有没有更好的办法生成自己想要的json ?
- 关于DataSet对象的一点疑惑请大家进来帮忙指点一下,谢谢了/.
- 有在winform下用的html编辑器控件吗?想做WINFORM版的新闻系统
如果是html的话
<input id="button" name="button" type="button" onclick="事件">
如果是cs中定义
Button bt=new Button();
bt.ID="mybtn";
bt.Attributes.Add("onclick","事件");
关于加载控件button,我的处理方法是:
1.用户控件(mycontrol.ascx):
<asp:ImageButton ID="mybtn" runat="server" OnClientClick="javascript:announceTime();return false;" />
上面用的是服务器控件,html控件的方法我也试过了,不行。