簡體   English   中英

刷新頁面並打開新的新窗口

[英]Refresh page and open new new window

我有一個頁面在燈箱內顯示一些內容,在此內容內有一個按鈕(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);
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM