如何在UpdatePanel中调用JS客户端脚本
2012-12-15 16:26
441 查看
页面中加入了UpdatePanel后,Response.Write("<script>function dis (){alert('这是调用写在server的JS');}</script>")来调用客户端脚本,无任何提示的无反应。如何在UpdatePanel中调用JS客户端脚本呢?
方法:采用 ScriptManager.RegisterStartupScript(Control controlId,Type this.GetType(),String key,String script block)方法。
有人说controlId必须是UpdatePanel里的,其实不然,page控件就可以。
下面给出一个具体的实例:
复制代码 代码如下:
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(BtnJs, this.GetType(), "alert", "<script>function
dis (){alert('这是调用写在server的JS,如用Response.Write()是不能实现此效果的!!! ');}</script>", false);
复制代码 代码如下:
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" >
</asp:ScriptManager>
<input id="BtnJs" type="button" value="CallServerJs" onclick="dis()" runat="server"/>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" RenderMode="Block">
<ContentTemplate>
<asp:Button ID="Button6" runat="server" Text="Button" OnClientClick="dis()"/>
</ContentTemplate>
</asp:UpdatePanel>
注意:BtnJs是UpdatePanel外的按钮 同时Button6重用了服务端注册的脚本附带说一下,如果是在普通的aspx中希望在服务器端注册下客户端脚本,可以用
Page.ClientScript.RegisterStartupScript(this.GetType(), String Key,String Js block ,Bool AddScriptTag),除了注意粗体字以外,其他操作同上。紫色部分不能包含,如写了的话,浏览时会将脚本部分自动注释掉!
方法:采用 ScriptManager.RegisterStartupScript(Control controlId,Type this.GetType(),String key,String script block)方法。
有人说controlId必须是UpdatePanel里的,其实不然,page控件就可以。
下面给出一个具体的实例:
复制代码 代码如下:
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(BtnJs, this.GetType(), "alert", "<script>function
dis (){alert('这是调用写在server的JS,如用Response.Write()是不能实现此效果的!!! ');}</script>", false);
复制代码 代码如下:
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" >
</asp:ScriptManager>
<input id="BtnJs" type="button" value="CallServerJs" onclick="dis()" runat="server"/>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" RenderMode="Block">
<ContentTemplate>
<asp:Button ID="Button6" runat="server" Text="Button" OnClientClick="dis()"/>
</ContentTemplate>
</asp:UpdatePanel>
注意:BtnJs是UpdatePanel外的按钮 同时Button6重用了服务端注册的脚本附带说一下,如果是在普通的aspx中希望在服务器端注册下客户端脚本,可以用
Page.ClientScript.RegisterStartupScript(this.GetType(), String Key,String Js block ,Bool AddScriptTag),除了注意粗体字以外,其他操作同上。紫色部分不能包含,如写了的话,浏览时会将脚本部分自动注释掉!
您可能感兴趣的文章:
相关文章推荐
- UpdatePanel 加载后 调用Js脚本
- UpdatePanel中内容异步加载后,调用JS脚本方法
- UpdatePanel 更新后JS调用UpdatePanel外控件
- UpdatePanel里如果要调用JavaScript脚本应注意
- UpdatePanel 后台常调用的的JS语句
- Jquery如何序列化form表单数据为JSON对象 C# ADO.NET中设置Like模糊查询的参数 从客户端出现小于等于公式符号引发检测到有潜在危险的Request.Form 值 jquery调用iframe里面的方法 Js根据Ip地址自动判断是哪个城市 【我们一起写框架】MVVM的WPF框架(三)—数据控件 设计模式之简单工厂模式(C#语言描述)
- 使用js脚本如何进行客户端验证时出现乱码怎么办?
- 在asp.net UpdatePanel 执行脚本JS
- js 脚本无法控制的地方. 该死的UPdatepanel.使用UPdatepanel页面不visual studio 不报错.
- Asp.net中如何在客户端JS中调用服务器端方法
- 使用js脚本如何进行客户端验证时出现乱码怎么办?
- UpdatePanel完成后调用js
- js前台与后台数据交互-后台调前台(后台调用、注册客户端脚本)
- UpdatePanel中用后台CS代码调用JS代码,先执行控件事件,后触发JS
- UpdatePanel完成后调用js
- Updatepanel中对写入的脚本如何运行?
- iframe中的js如何调用父页面中模块化好的脚本中的方法?
- AJAX.net 客户端JS调用服务端事件 UpdatePannel无刷新更新
- updatepanel刷新后重新加载js脚本问题
- ASP.net应用程序中如何调用客户端的Javascript脚本小结(转)