ScriptManager.RegisterStartupScript方法/在局部刷新的部分不能实现response.write的功能

原文链接:https://blog.csdn.net/harbour_bin/article/details/10963555

问题:在局部刷新的部分不能实现response.write的功能?

解决方法:

如果页面中不用Ajax,cs中运行某段js代码方式可以是:
Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "<script>window.open('default2.aspx')</script>");
如果页面中使用了Ajax ,则上述代码即使执行也无效果。对这种情况我们通常采用:
ScriptManager.RegisterStartupScript(this.Button1, this.GetType(), "alertScript", "window.open('default2.aspx');", true);
其中第一个参数为要注册脚本的控件ID,试了一下,只要是本页面的就行。
第二个参数为注册脚本控件类型,是控件还是this的GetType()都可以,typeOf(string)也没问题.
第三个脚本函数的名字,随便起。
第四个是脚本内容。
第五个是标明是否再添加脚本标签,如果第四个参数里包含了<script></script>标签,此处则为false,否则为true。

打开新页面,代码:

ScriptManager.RegisterStartupScript(UpdatePanel3, Page.GetType(), System.DateTime.Now.Ticks.ToString(),"window.open('index.aspx');", true);

弹出窗口,代码:

ScriptManager.RegisterStartupScript(UpdatePanel3, Page.GetType(), System.DateTime.Now.Ticks.ToString(),"alert('购物车不能为空,请重新选购!')" ;true);

posted @   yinghualeihenmei  阅读(16)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· Obsidian + DeepSeek:免费 AI 助力你的知识管理,让你的笔记飞起来!
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2023-06-17 C# 报错:xxx正由另一进程使用,因此该进程无法访问此文件
2023-06-17 未授权访问
2022-06-17 将项目放在svn上
点击右上角即可分享
微信分享提示