I have an app written in ASP.NET where one of the web pages opens up a web page in a second window. When this second web page closes, the first web page needs to update its data. How do you do this?
![]() |
0 |
![]() |
You can have the child window call a parent method when the user clicks a link to close it.
Otherwise, you'd have to set up polling to check for the existence of the child, and refresh if it doesn't exist.
Please Mark As Answer posts that helped you.
"If we learn from our mistakes, I should be brilliant by now."
![]() |
0 |
![]() |
Thanks, this gives me part of the answer (in that it shows how to call a function on a parent page). However, there's a major issue with timing. I need the parent page function to be called AFTER the submit button's event handler fires.
![]() |
0 |
![]() |
OK, I think I figured it out. There's an onunload event.
But that brings me to the next issue. How do I trigger a post back in the button_click() method? I want to re-execute the Form_Load event handler. I do not want to submit the form.
function button_click(){
document.getElementById("btnSubmit").click();}
![]() |
0 |
![]() |
OK, I tried using the onunload event. Unfortunately, this event fires for anything that causes a postback and I just want it when the user clicks the Submit button.
![]() |
0 |
![]() |
Does anyone know how to do this? I have an app where one of the pages opens a second page. When the second page closes, the first page needs to refresh.
![]() |
0 |
![]() |
Hi,
I guess you want to display the new data in the parent page when child page is closed, for instance, re-query data from database and display it in page. If so, we don't need to reload the page, you can write retrieve new data function and display them in button submit event.
I look forward to hearing from you.
Thomas Sun
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
![]() |
0 |
![]() |
it helps me lot also.
replica handbags
replica purses
![]() |
0 |
![]() |
> I guess you want to display the new data in the parent page when child page is closed,
Yes.
> for instance, re-query data from database and display it in page.
Well, the data is stored in Session, but yes.
> If so, we don't need to reload the page, you can write retrieve new data function and display them in button submit event.
Where? How? This is still my first question. If the submit button is on the child page, how does the parent know that the child page has been submitted?
![]() |
0 |
![]() |
look NeoRev : hopes this will help you.....
open the second page in a dialoge from the first page
var objValue= window.showModalDialog('Secondpage.aspx','desc','dialogWidth:700px;dialogHeight=435px;resizable=0;scroll=0;');
and in the second page write the following code when you close the window try to use the followin code
var objRet =new Object();
objRet.RetText ="return some value";
window.returnValue=objRet;
window.close();
again in the first page use
if (objValue=="some value returned from second page" )
{
call some button's postback event which will load the data;
}
for further query ask me.
Shafiul hasan md. tareq
plz marked as answer if it helps you for future developers who are facing same problem.:)
![]() |
0 |
![]() |
> open the second page in a dialoge from the first page
> var objValue= window.showModalDialog('Secondpage.aspx','desc','dialogWidth:700px;dialogHeight=435px;resizable=0;scroll=0;');Thanks, I started adding the code you suggested but now whenever there's a postback on the child page, the Session gets cleared. Unfortunately, the app keeps a lot of data in session, so this is kind of a deal breaker if I can't access the session.
![]() |
0 |
![]() |
Apparently, this session state issue is a bug in IE.
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=767598&SiteID=1
If anyone has any other ideas on how to do this, please let me know.
Thanks.
![]() |
0 |
![]() |
Hi,
NeoRev:
> If so, we don't need to reload the page, you can write retrieve new data function and display them in button submit event.
Where? How? This is still my first question. If the submit button is on the child page, how does the parent know that the child page has been submitted?
I modified the example in http://www.kaelisspace.com/wordpress22/2008/06/26/cnet-how-to-call-parent-method-from-popup/, and you can try the following code. Parent.aspx:
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Session["Data"] = "Hello world!"; Response.Write(Session["Data"].ToString()); } } protected void btnSubmit_Click(object sender, EventArgs e) { Response.Write(Session["Data"].ToString());//We can update display here. } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Example Parent Page</title> <script type="text/javascript"> function button_click() { document.getElementById("btnSubmit").click(); } </script> </head> <body> <form id="form1" runat="server"> <div> <a href="#" onclick="window.open('child.aspx','popup');return false;">Open Child Page and Change Session Data</a><br /> <asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="Submit" /></div> </form> </body> </html>Child.aspx
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void btnSubmit_Click(object sender, EventArgs e) { Session["Data"] = "I am from child page!";//Change session data here. Response.Write("Session Data has been changed to"); Response.Write("<br />"); Response.Write(Session["Data"].ToString()); } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Example Child Calling Parent Method</title> <script type="text/javascript"> function callAndClose() { if (self.opener && self.opener.button_click) { var opener = self.opener; self.opener = self; opener.button_click(); self.close(); } } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="Change Session data" /> <br /> <br /> <a href="#" onclick="callAndClose();">Close Child Page and Update parent page Session data</a> </div> </form> </body> </html>
I look forward to hearing from you.
Thomas Sun
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
![]() |
0 |
![]() |
Thanks, Thomas, but how does this address the previous issue with this code (the parent page's function needs to be called AFTER the child's submit button's event handler fires)?
![]() |
0 |
![]() |
Hi,
In this case, we simulate button click that is in the parent page from child page using JavaScript. "self.opener" refers to the window that opened this one and we call opener's button_click event which triggers the update button click event in the codebehind.
Thanks.
Thomas Sun
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
![]() |
0 |
![]() |
But callAndClose() needs to be called when the child's submit button is clicked. In the example provided, the submit button doesn't even call the callAndClose() method. It's called by a separate hyperlink:
<asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="Change Session data" />
<br />
<br />
<a href="#" onclick="callAndClose();">Close Child Page and Update parent page Session data</a>If I modify this code to put the hyperlink around the button...
<a href="http://forums.asp.net/AddPost.aspx?ReplyToPostID=2567976&Quote=False#" onclick="callAndClose();">
<asp:imagebutton id="btnSave" runat="server" Width="60px" AlternateText="Submit" ImageUrl="images/saveButton.gif"
Height="20px" meta:resourcekey="btnSaveResource1">
</asp:imagebutton>
</a>...the callAndClose gets called before the Submit button's server-side event handler.
![]() |
0 |
![]() |
Hi,
Do you mean you want to call this JavaScript function in the child's submit button in the codebehind? If so, we can use RegisterStartupScript method to do this.
For example, I modified the Child.aspx as follow:
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void btnSubmit_Click(object sender, EventArgs e) { Session["Data"] = "I am from child page!"; Response.Write("Session Data has been changed to"); Response.Write("<br />"); Response.Write(Session["Data"].ToString()); Page.ClientScript.RegisterStartupScript(this.GetType(),"update", "callAndClose()",true); } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Example Child Calling Parent Method</title> <script type="text/javascript"> function callAndClose() { if (self.opener && self.opener.button_click) { var opener = self.opener; self.opener = self; opener.button_click(); } } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="Change Session data and Update parent page Session data " /> <br /> <br /> </div> </form> </body> </html>I look forward to hearing from you.
Thomas Sun
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
![]() |
0 |
![]() |
OK, I think I got everything working (for now) on the child page. However, I'm having an issue with the parent page. I need for the parent page to reload. I tried document.getElementById("btnReload").click() and ASP.NET's __doPostBack() method. Neither cause the parent to reload and the child no longer closes. My code is below. I put two alert() statements in there for debugging purposes. The first message box is displayed but not the second one.
function button_click(){
alert("Entering EditQuestionnaireData.button_click"); //document.getElementById("btnReload").click();__doPostBack("__Page", "MyCustomArgument");alert("Exiting EditQuestionnaireData.button_click");}
<asp:Button ID="btnReload" runat="server" Visible="false" OnClick="btnReload_Click" Text="Reload"></asp:Button>
![]() |
0 |
![]() |
Ah-ha, the issue with the parent page not reloading (at least with document.getElementById("btnReload").click) was that the btnReload's Visible property was set to false. I changed it to....
<asp:Button ID="btnReload" style="display:none" runat="server" OnClick="btnReload_Click" Text="Reload"></asp:Button>
...and now it appears to be working.
![]() |
0 |
![]() |