Refreshing parent page from a child page opened as a modal dialog box

Discussion in 'ASP .Net' started by Bali, Oct 31, 2008.

  1. Bali

    Bali Guest

    Default.aspx is the starting page containing a control(ascx) which
    has
    asp:button control on it. On the button click event it has to open a
    new page as a modal control. Since refreshing a page in a dialog box
    ended up opening up a new browser window with the aspx page, I read
    on
    a forum that I should use the iframe control and since I have to open
    a bunch of pages as diaogboxes, I created a general
    page(Container.aspx) which has an iframe control on it, which I then
    pass a parameter(pageToGoTo) specifying the aspx page that has to be
    opened as a dialogbox.

    Sequence of events and code are as follows:


    On the default.aspx page I have added a control with a button. On the
    button click server side event on that control, I call an aspx page.


    string script = String.Format("window.showModalDialog(\"{0}?
    pageToGoTo=testWebForm01.aspx\", \"testWebForm01.aspx
    \" ,'dialogWidth=520px;dialogHeight=650px;dialogTop=125px;dialogLeft=125px;');­",
    ResolveUrl("~/Container.aspx"));
    Page.ClientScript.RegisterStartupScript(GetType(),
    "test",
    script, true);


    On the Container.aspx I have an iframe control called frameTest which
    I load on Page_Load event as follows


    string pageToGoTo =
    Request.QueryString["pageToGoTo"];
    frameTest.Attributes["src"] = pageToGoTo;


    This is then able to load the testWebForm01.aspx in the iframe
    control.


    Now on a button click event on testWebForm01.aspx I want to close the
    testWebForm01 form and reload default.aspx so that the control on
    default.aspx. I added the following javascript code to
    testWebForm01.aspx


    function refreshParent()
    {
    window.opener.location.href = window.opener.location.href;


    if (window.opener.progressWindow)
    {
    window.opener.progressWindow.close()
    }
    window.close();


    // parent.refresh();
    // self.close();
    }


    and called it on the server side button_click event as follows


    string script = "refreshParent()";
    Page.ClientScript.RegisterStartupScript(GetType(),
    "test",
    script, true);


    I keep getting window.opener is null error.


    I read on another forum that if we have used showModalDialog method
    then window.opener method is not initialized.


    I did play around with trying to initialize it but haven't had any
    success.


    Does anybody have any idea on how refreshing the parent page can be
    accomplished? Please let me know.


    Thanks


    Sumeet
    Bali, Oct 31, 2008
    #1
    1. Advertising

  2. Bali

    bruce barker Guest

    Re: Refreshing parent page from a child page opened as a modal dialogbox

    you iframe does not have an opener, the page containing it does, so you
    want window.parent.opener (or however deep you are).

    as showModalDialog is now w3c complaint it a bad practice to start using
    it. now days this is usally done with a floating div (sometimes
    containing an iframe). usually the div is dislayed, and the background
    page is gray'd out. there are a lot of sample modal dialogs that work
    this way. there are several for jQuery and the ajax toolkit has one.

    -- bruce (sqlwork.com)


    Bali wrote:
    > Default.aspx is the starting page containing a control(ascx) which
    > has
    > asp:button control on it. On the button click event it has to open a
    > new page as a modal control. Since refreshing a page in a dialog box
    > ended up opening up a new browser window with the aspx page, I read
    > on
    > a forum that I should use the iframe control and since I have to open
    > a bunch of pages as diaogboxes, I created a general
    > page(Container.aspx) which has an iframe control on it, which I then
    > pass a parameter(pageToGoTo) specifying the aspx page that has to be
    > opened as a dialogbox.
    >
    > Sequence of events and code are as follows:
    >
    >
    > On the default.aspx page I have added a control with a button. On the
    > button click server side event on that control, I call an aspx page.
    >
    >
    > string script = String.Format("window.showModalDialog(\"{0}?
    > pageToGoTo=testWebForm01.aspx\", \"testWebForm01.aspx
    > \" ,'dialogWidth=520px;dialogHeight=650px;dialogTop=125px;dialogLeft=125px;');­",
    > ResolveUrl("~/Container.aspx"));
    > Page.ClientScript.RegisterStartupScript(GetType(),
    > "test",
    > script, true);
    >
    >
    > On the Container.aspx I have an iframe control called frameTest which
    > I load on Page_Load event as follows
    >
    >
    > string pageToGoTo =
    > Request.QueryString["pageToGoTo"];
    > frameTest.Attributes["src"] = pageToGoTo;
    >
    >
    > This is then able to load the testWebForm01.aspx in the iframe
    > control.
    >
    >
    > Now on a button click event on testWebForm01.aspx I want to close the
    > testWebForm01 form and reload default.aspx so that the control on
    > default.aspx. I added the following javascript code to
    > testWebForm01.aspx
    >
    >
    > function refreshParent()
    > {
    > window.opener.location.href = window.opener.location.href;
    >
    >
    > if (window.opener.progressWindow)
    > {
    > window.opener.progressWindow.close()
    > }
    > window.close();
    >
    >
    > // parent.refresh();
    > // self.close();
    > }
    >
    >
    > and called it on the server side button_click event as follows
    >
    >
    > string script = "refreshParent()";
    > Page.ClientScript.RegisterStartupScript(GetType(),
    > "test",
    > script, true);
    >
    >
    > I keep getting window.opener is null error.
    >
    >
    > I read on another forum that if we have used showModalDialog method
    > then window.opener method is not initialized.
    >
    >
    > I did play around with trying to initialize it but haven't had any
    > success.
    >
    >
    > Does anybody have any idea on how refreshing the parent page can be
    > accomplished? Please let me know.
    >
    >
    > Thanks
    >
    >
    > Sumeet
    bruce barker, Nov 1, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lisa
    Replies:
    1
    Views:
    493
    Matt Berther
    Jan 18, 2005
  2. Samy
    Replies:
    2
    Views:
    1,353
  3. Bali
    Replies:
    0
    Views:
    434
  4. gopal srinivasan
    Replies:
    0
    Views:
    232
    gopal srinivasan
    Nov 5, 2004
  5. Bali
    Replies:
    9
    Views:
    275
    Dr J R Stockton
    Nov 4, 2008
Loading...

Share This Page