给出简单代码说明:
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.NET1.1要實現下件的下載,在線等待..
- 用Label控件绑定数据时,若数据很长的话,如何让它换行?
- 哪里有C#的群就是发什么问题都能解决一下的那种`
- 动网论坛的帖子前一贴后一贴不是真正的!!
- 导入什么命名空间!
- 弱弱的问一下,关于显示flash的问题!
- 关于水晶报表的打印
- 提示@subject,@content,@id未声明,请问错在哪里?
- 关于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控件的方法我也试过了,不行。