By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,067 Members | 1,818 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,067 IT Pros & Developers. It's quick & easy.

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

P: n/a
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=1 25px;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
Oct 31 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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=1 25px;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
Nov 1 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Browse more ASP.NET Questions on Bytes