我在按钮点击事件结束时获得了一些代码,该事件使用RegisterStartupScript打开一个新的Windows(它是一个报告供用户打印)
页面加载后,我想将用户从数据输入页面重新引导回默认页面,但如果我在其中放置Response.Redirect
则不会打开我的弹出窗口。知道弹出窗口为什么不会开火?
这是c#代码:
string myRptURL = "EstimateReport.aspx?id=" + hiddenID.Value;
string script = "window.open('" + myRptURL + "','')";
ClientScript.RegisterStartupScript(this.GetType(), "OpenWin", "<script>openNewWin('" + myRptURL + "')</script>");
Response.Redirect("default.aspx?mess=" + Server.UrlEncode("New Estimate Created"));
这是Javascript函数:
<script language="javascript" type="text/javascript">
function openNewWin(url) {
var x = window.open(url, 'mynewwin', '_blank', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=520,modal=yes,alwaysRaised=yes');
x.focus();
}
答案 0 :(得分:3)
Response.Redirect
正在取消脚本,因为它没有发送到客户端。用javascript重定向。
ClientScript.RegisterStartupScript(this.GetType(), "OpenWin",
"<script>openNewWin('" + myRptURL + "','" + "default.aspx?mess=" +
Server.UrlEncode("New Estimate Created") + "')</script>");
function openNewWin(url, redirectUrl) {
var x = window.open(url, 'mynewwin', '_blank', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=520,modal=yes,alwaysRaised=yes');
x.focus();
window.location = redirectUrl;
}