刷新页面并打开新窗口
问题描述:
我有一个页面显示灯箱内的一些内容,在这个内容中有一个按钮(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);
}
如果我更改顺序,我将刷新页面,但不会打开新的一页
答
所以,我的意思是这样:
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
btn.Text = "Refreshed";
if (Request.Params["btnPressed"] != null && Request.Params["btnPressed"] == "true")
{
ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow", "window.open('MyPage.aspx');", true);
}
}
protected void btn_Click(object sender, EventArgs e)
{
btn.Text = "Not Refreshed";
lbl.Text = "Not Refreshed";
System.Threading.Thread.Sleep(1000);
////to refresh the page
Page.Response.Redirect(HttpContext.Current.Request.Url.ToString()+"?btnPressed=true", true);
}
}
我想这是因为你结束的响应,否则该网页将被刷新。 它不是最好的,但我可以想到这个解决方案 - >当按下按钮时,您使用Response.Redirect(HttpContext.Current.Request.Url.ToString()+“?btnPressed = true”); 然后在页面加载方法中,使用“if query string is btnPressed ... ect,then - > ScriptManager.RegisterStartupScript(Page,typeof(Page),”OpenWindow“,”window.open('URL') ;“,true); – 2014-11-07 00:02:27
Hi Ziv,谢谢你的回答!很抱歉,我没有完全遵循你的解决方案请你再解释一次。先谢谢了! – Carlos 2014-11-07 00:13:22
最好的方法是在代码中,看到我的解决方案 – 2014-11-07 01:31:12