Web page opens second web page, how does first page know when the second one closes?

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
NeoRev
8/12/2008 7:22:22 PM
asp.net.getting-started 91979 articles. 4 followers. Follow

18 Replies
1634 Views

Similar Articles

[PageSpeed] 10

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
nikki_doer_of_things
8/12/2008 8:09:57 PM
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
NeoRev
8/15/2008 2:57:41 PM

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
NeoRev
8/15/2008 3:35:59 PM

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
NeoRev
8/15/2008 6:26:29 PM
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
NeoRev
8/15/2008 6:56:44 PM

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
Thomas
8/18/2008 6:38:39 AM

it helps me lot also.


replica handbags
replica purses
0
dorlex
8/18/2008 7:01:03 AM

> 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
NeoRev
8/18/2008 11:24:24 AM

 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
Tareq_sust
8/18/2008 12:27:03 PM

>  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
NeoRev
8/18/2008 1:11:24 PM

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
NeoRev
8/18/2008 1:24:09 PM

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
Thomas
8/19/2008 2:26:59 AM

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
NeoRev
8/19/2008 1:04:31 PM

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
Thomas
8/20/2008 2:42:34 AM

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
NeoRev
8/20/2008 2:15:36 PM

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
Thomas
8/21/2008 3:24:29 AM

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
NeoRev
8/21/2008 4:37:50 PM

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
NeoRev
8/21/2008 6:16:25 PM
Reply:

Similar Artilces:

How to open another web page from one web page
Hi, I am writing an asp.net(C#) 2.0 web page with a link to another web page by clicking a button control on the page, so how can I link it in the codes? I cannot access another aspx page class within the current aspx page class.  Thanks If you need to re-direct the user to another page after pressing your Button, then use the Response.Write method like so: Response.Redirect("~/Default.aspx")Thanks, EdMicrosoft MVP - ASP/ASP.NET 1) Response.Redirect( "Destination PageName");2) Response.Transfer("Destination PageName");3) Hyperlink(  set Url="...

How to keep second page at the same postion as first page when loading the second one
Hello:  I have the submit bottom form first page. After clicking submit bottom, the second page position is not the same as first page when loading. How to keep the second page the same position when loading. Your help is highly appreciated.    Are you talking about the scroll position of the page? I'll assume so. I guess it depends on whether you are posting back and returning the same page, in other words user clicks submit button in page1 which posts back page1 and returns page1 to the browser or you are posting back page1 and then taking the user to a com...

how to navigate the url page in one web application page to another web application page
In my project one solution have 2 web apllications in one folder.like 1.webapplication1 2.webapplication2. in firt webapplication1 i created one aspx page like sample.axpx. in second webapplication2 i created one aspx page like sample2.aspx... in sample2.aspx page have hyperlinl. I need to navigate this hyperlink when i click it go to the sample.axpx. how can i write navigate url for this...help me. ..thanks  As i understand u, you need Multi Project soltuionsee this link, http://community.rainbowportal.net/blogs/jonathans_rainbow_blog/archive/2006/02/19...

Do not get expected WEb page on secondary
netware 6.5 sp2 Have setup a web page on a seconary IP address Load appache with the following command line LOAD ADDRESS SPACE = CSMI APACHE2 -f SYS:APACHE2\CSMI\SERVER\HTTPD.CONF Where HTTPD.CONF is set up to Listen 172.16.212.2:80 which is a secondary ip address A display secondary ipaddress at the server lists the seconary ipaddress I can ping the secondary ip address from the client in Remote manager using IP Address management the secondary IP addresses are not listed When I attempt to brose to the HTTP://172.16.212.2 address I do not see the web page I...

how to open a web page in form of a popup web page
Hello, I have two web pages, let say. Page A : With a Button on it. PAge B: with some info. Now I need to: When I click on the Button of page A.Page B must open in a pop up window.  I can do this but problem is this when I clicked on the button for first time it does not show me any thing and when I clicked on the button for second time then It shows me Page B .My code is as follow:  1 protected void Page_Load(object sender, EventArgs e) 2 { 3 if (!this.Page.IsPostBack) 4 { 5 6 } 7 else 8...

All web pages hang on web server when one of the web pages calls a run away sql query
Hi: We have a Windows 2003 dedicated web server running the .NET Frameworks 1.0 and 2.0.  We have a SQL Server cluster running SQL Server 2000.  Unfortunately, we do not have a test environment.  I have 2 .NET web sites in production.  My coworker has a voting .NET web page using AJAX on the same server.  The coworker wrote a query that was not indexing properly and when the page fired the query...the cluster went to almost 100% utilization.  My two web pages would hang and show a blank white page on the default.aspx.  Neither of m...

Paging Paging Paging
I am trying to do paging with my search results and it isnt working very well. Here is what I've tried and I feel I've tried everything, lol, please help me out. Sub DataGrid1_SortCommand(Sender as object, e as DataGridSortCOmmandEventArgs) DataGrid1.DataBind() End Sub Sub Datagrid1_PageIndexChanged(Sender as object, e as DataGridPageChangedEventArgs) Dim ds as dataSet DataGrid1.CurrentPageIndex = e.NewPageIndex if Session("Search") is nothing then 'Session probably has expired, get the datasource from database Datagrid1.DataSource = ...

How to databind control in one web page from another web page
Hi all,  I have a listbox control and a button control in a web page. Once the user clicks the button another web page is opened. The new web page will accept some data from the user which will be used to databind the listbox in the first web page. In other words, the two web pages ( the parent window and the child window) are open at the same time. The child page needs to databind a control in the parent page. Is there a way to do it? I need some code. Thx in advance Update: I hate to do this. Looks like I will have to take help of viewstate and session si...

Getting a list of all pages and all web parts on one page
Hi, is it possible to get a list of all pages in the portal in, for example, a treeview, with the WebParts info dynamic loaded from Personalization? Something like: Page1    WebPart1        WebPartProperty1        WebPartProperty2    WebPart2        WebPartProperty1Page2    WebPart1.... The pages (info) is actually stored in a DB and retrieved dynamic on loading (pretty much as I tried to explain on my blog). I'm using a MasterP...

Is it possible to embed part of one web page into another web page?
Any answers will be highly appreciated.  Thanks. If you can adjust the page you want to embed onto the other page, you could use a .ascx (web forms control).  Then you can add controls to it and just drag and drop it using VS.NET from the Solution Explorer window to the webform.  You can then also embed it onto other pages in that same web project easily by drag n drop.  I hope this helps, it's not exactly a portion of a web page but may be an acceptable alternative for you.Rachel AppelMVP - ASPInsider In order to better answer this, I could use some details as ...

how to open another web page and my first page still opend
i want to open 2 pages pub when i write Response .Redirect ("default2.aspx"); my first page disapeare and i get new page i want to open new page page still opend   thenks for your helhow could i add an asp.net button and determine its location in run time Use window.open javascript as discussed in this post.http://forums.asp.net/p/883647/919412.aspxHope this helps.  try this :  SelectedURL ="www.google.com" img.OnClientClick = "window.open('" + SelectedURL + "');return false;"; where img is a button  if you cl...

How to get HTML Source of web page opened by web browser using vb.net
hello friends,         i have opened an web browser in vb.net using the below code Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim nullObject As System.Object = 0 Dim str As String = "" Dim nullObjStr As System.Object = str Windows.Forms.Cursor.Current = Cursors.WaitCursor Dim i As Int16 For i = 1 To 2 AxWebBrowser1.Navigate("http://www.google.co.in/search?hl=en&q=test&meta=", True) AxWebBrowser1.Document. Next Windows.Forms.Cursor.Current = Cursors.Default End Sub  ...

link a web page to another web page?
I have a web page with my banner and buttons for my site on it. I want to add this to all of my pages. Instead of copying a pasting that to every page. Is there a way i can link the pages to the banner page? Thanx use ascx?:) Or you could create a template page. That is: Create a page inherited from System.Web.UI.Page and place your banner and buttons in this and then have all your other pages inherit tis custom page instead of System.Web.UI.Page. ...

parent web page --child web page
Dear Developers , how to get values child web page values to parent web page ? For the example , I have parent Employee Address. and child Page have employee personal address.. when i access the Parent page , there is no employee address means ..child page pop rises , after complete child page then only , i can access the parent page.. how to i do .. Thanking u raja Thanks,Regards,Rajamsrasa@yahoo.com...

Web resources about - Web page opens second web page, how does first page know when the second one closes? - asp.net.getting-started

Close front rounded vowel - Wikipedia, the free encyclopedia
. Across many languages, it is most commonly represented orthographically as ⟨ ü ⟩ (in German and Turkish) or ⟨y⟩, but also as ⟨u⟩ (in French ...

Landslide closes lane of Snowy Mountains Highway on Brown Mountain
A landslide has closed one&nbsp;one eastbound lane east of the the Snowy Mountains highway on&nbsp;Brown Mountain.

Hearst’s Sites Close 2015 Strong
Hearst’s collection of sites—overseen by Hearst Magazines Digital Media (HMDM)—enjoyed a strong end to 2015. In December, HMDM traffic hit an ...

The curtain closes for the Yahoo Screen video hub
... , Your Apple TV’s Siri can now search PBS and PBS Kids , and ‘Downton Abbey’ creator unveils ‘Belgravia,’ a digital novel . The curtain closes ...

KU's Frank Mason III Was Ridiculously Close to OU's Buddy Hield on Crucial Steal - Bleacher Report
Kansas guard Frank Mason III has zero regard for personal space. Just ask Oklahoma star Buddy Hield. With 12 seconds left in Monday night’s third ...


Obama moves to close loopholes for gun background checks
The administration on Monday announced a series of executive actions they'll implement to reduce gun violence

Dow closes down triple digits, posts worst opening day in 8 years
U.S. stocks closed lower, weighed by renewed concerns of global economic slowdown and increased tensions in the Middle East.

New Supreme Leader Snoke Close-Up Photo From Star Wars: The Force Awakens Released
Following yesterday's first official look, Entertainment Weekly have shared (via Twitter, [...]

Patriots close regular season on unfamiliar low note
The Patriots have never closed out the regular season under Bill Belichick as poorly as they have in 2015.

Resources last updated: 1/6/2016 7:02:50 AM