AJAX下不能使用RESPONSE.WRITE 脚本的解决方案
来源:互联网 发布:威廉古堡 知乎 编辑:程序博客网 时间:2024/05/06 20:11
在使用ASP.NET AJAX 开发程序时候 我们以往经常使用 response.write();不能使用。
使用ScriptManager来实现JS注册即可
以前以下代码现在不能在AJAX环境下正确运行
protected void Button1_Click(object sender, EventArgs e)
...{
Response.Write("<script>window.open("http://www.baidu.com/");</script>");
}
...{
Response.Write("<script>window.open("http://www.baidu.com/");</script>");
}
我们修改以上代码 让他在AJAX下运行起来
这里的ScriptManager.RegisterStartupScript()为静态方法,注册客户端脚本。第一个参数UpdatePanel1 为JS要输出到的UpdatePanel,opennewwindow 脚本关键字
protected void Button1_Click(object sender, EventArgs e)
...{
//Response.Write("<script>window.open("http://www.baidu.com/");</script>");
ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(UpdatePanel), "opennewwindow", "window.open("http://www.baidu.com/");", true);
}
...{
//Response.Write("<script>window.open("http://www.baidu.com/");</script>");
ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(UpdatePanel), "opennewwindow", "window.open("http://www.baidu.com/");", true);
}
前台ASPX代码
<form id="form1" runat="server">
<div>
<asp:ScriptManager id="ScriptManager1" runat="server">
</asp:ScriptManager>
</div>
<asp:UpdatePanel id="UpdatePanel1" runat="server">
<contenttemplate>
<asp:Button id="Button1" runat="server" Text="Button" OnClick="Button1_Click"></asp:Button>
</contenttemplate>
</asp:UpdatePanel>
</form>
<div>
<asp:ScriptManager id="ScriptManager1" runat="server">
</asp:ScriptManager>
</div>
<asp:UpdatePanel id="UpdatePanel1" runat="server">
<contenttemplate>
<asp:Button id="Button1" runat="server" Text="Button" OnClick="Button1_Click"></asp:Button>
</contenttemplate>
</asp:UpdatePanel>
</form>
- AJAX下不能使用RESPONSE.WRITE 脚本的解决方案
- AJAX下不能使用RESPONSE.WRITE 脚本的解决方案
- Ajax中使用Response.Write输出javascript脚本出错的解决方案
- 含Ajax项目的 Response.Write 使用
- Ajax中使用Response.Write输出javascript脚本出错的解决办法
- Ajax中使用Response.Write输出javascript脚本出错的解决办法
- Ajax中使用Response.Write输出javascript脚本出错的解决办法
- Ajax中使用Response.Write输出javascript脚本出错的解决办法
- Ajax中使用Response.Write输出javascript脚本出错的解决办法
- Response.Write("...")与 Response.Redirect("...")不能同时使用
- 解决Response.Redirect和 Response.Write不能同时使用
- updatePanel中的button的click事件中不能使用response.write()
- 后台代码里执行弹出脚本方法!(Response.Write), Response.Write()彈窗的方法大全
- ASP.NET AJAX使用UpdatePanel控件+Response.Write()报错
- response.getWriter().write()用于ajax
- Response.write 之后 前台不能获取正确的返回串
- Response.Write结合alert的利弊及解决方案
- ajax.net中Response.Write()的处理方法
- 根据IP得到主机名
- xml schema
- SSPI
- aspjpeg的高级用法
- 找到锁住文件的进程
- AJAX下不能使用RESPONSE.WRITE 脚本的解决方案
- 读写文件
- asp.net 图片压缩和判别类
- Sys.WebForms.PageRequestManagerParserErrorException 错误的解决办法
- C#编程入门之类型和变量
- 在Dreamwever中可视化编辑rhtml页面
- sqlserver中获取执行sql语句时间的方法
- 获取PE文件的导出函数列表
- vcleaner 辞职日记摘录(1)