0

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

Carlos
  • 377
  • 5
  • 24
  • I guess it is because you are ending the response, otherwise the page would be refreshed. Its not the best but I can think of this solution-> when button is pressed you use Response.Redirect(HttpContext.Current.Request.Url.ToString()+"?btnPressed=true"); Then on your page load method, use "if query string is btnPressed... ect, then--> ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow", "window.open('URL');", true); – Ziv Weissman Nov 07 '14 at 00:02
  • Hi Ziv, thank you for your answer! I am sorry but i don't quite follow your solution Would you please explain it one more time. Thank you in advance! – Carlos Nov 07 '14 at 00:13
  • the best way is in code, see my solution. – Ziv Weissman Nov 07 '14 at 01:31

1 Answers1

0

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);
    }
}
Ziv Weissman
  • 4,400
  • 3
  • 28
  • 61