简体   繁体   中英

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. I want to refresh the page and open a new window(or the other way around) all this from 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);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM