我有一个页面在灯箱内显示一些内容,在此内容内有一个按钮(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);
}
}