【发布时间】:2014-11-07 09:31:46
【问题描述】:
我有一个页面在灯箱内显示一些内容,在此内容中有一个按钮 (btnAccept) 来确认。我想从 codeBehind (c#) 刷新页面并打开一个新窗口(或相反)。我将不胜感激。
这是我迄今为止尝试过的:
第一次尝试:我可以打开一个新窗口,但我无法刷新页面
protected void btnAccept_Click(object sender, EventArgs e)
{
//to open the new tab
Response.Redirect(URL, true);
//to refresh the page
Page.Response.Redirect(HttpContext.Current.Request.Url.ToString(), true);
}
第二次尝试:我可以打开一个新窗口,但我无法刷新页面
protected void btnAccept_Click(object sender, EventArgs e)
{
//to open the new tab
ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow", "window.open('URL');", true);
//to refresh the page
Page.Response.Redirect(HttpContext.Current.Request.Url.ToString(), true);
}
如果我更改顺序,我将刷新页面但不会打开新页面
【问题讨论】:
-
我猜是因为你正在结束响应,否则页面会被刷新。它不是最好的,但我能想到这个解决方案->按下按钮时使用 Response.Redirect(HttpContext.Current.Request.Url.ToString()+"?btnPressed=true");然后在您的页面加载方法上,使用“如果查询字符串是 btnPressed... 等,则 -> ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow", "window.open('URL');",真);
-
您好 Ziv,谢谢您的回答!很抱歉,但我不太了解您的解决方案,请您再解释一次。提前谢谢!
-
最好的办法是在代码中,看我的解决方案。
标签: javascript c# code-behind