[英]Refresh page and open new new window
I have a page that displays some content inside a lightbox, within this content there is a Button (btnAccept) to confirm. 我有一个页面在灯箱内显示一些内容,在此内容内有一个按钮(btnAccept)进行确认。 I want to refresh the page and open a new window(or the other way around) all this from codeBehind (c#) .
我想刷新页面并从codeBehind(c#)打开一个新窗口(或相反)。 I will appreciate any help.
我将不胜感激。
this is what I tried so far: 这是我到目前为止尝试过的:
First attempt: I am able to open a new window but I CAN'T refresh the page 第一次尝试:我可以打开一个新窗口,但无法刷新页面
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);
}
Second attempt: I am able to open a new window but I CAN'T refresh the page 第二次尝试:我可以打开一个新窗口,但无法刷新页面
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);
}
if I change the order i will refresh the page but WILL NOT open a new page 如果我更改顺序,我将刷新页面,但不会打开新页面
So, what i mean is do this: 所以,我的意思是这样做:
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);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.