views:

527

answers:

3

I'm working on a page, in which other pages are opened from it in a modal way. I need to call function exists in opener page to update certain controls in it.

I'm using window.open to open another window but in this case Page.PreviousPage for opened page is null.

I'm using

<%@ PreviousPageType VirtualPath="~/PreviousPage.aspx" %>

to refer to Previous Page.

Any suggestions?

FYI: all aspx pages are AJAX-Enabled.

A: 

I'm just wondering if you can use a UpdatePanel control to do this for you. Maybe via a master page. Admittedly i've had hardly any experience with AJAX so i might be incorrect. (Apologies if i am)

Here is a useful link about using the Update Panel

kevchadders
+2  A: 

You can't call a method in the code behind of a Page class to update controls in a page that is displayed. The instance of the Page class only exists while the page is rendered, once the page is displayed in the browser, the Page object no longer exists.

The PreviousPage property is used when you make a post from one page to another, but it doesn't contain the Page object that was used to render the page, it contains a recreated Page object that will not be used to render anything at all. You can only use it to read information from the fields based on the information that was posted from it.

If you want to update the opener page you either have to do it on the client side using Javascript (), or reload the page so that the server side code can repopulate it. A combination of them both would be to use AJAX to update the page.

Edit:
You can for example use Javascript to access the opener and change the content of an element:

window.opener.document.getElementById('Info').innerHTML = 'updated';

You can also call a Javascript function in the opener page:

window.opener.doSomething('data');

That which gives you more possibilities, like making an AJAX call to load data from the server.

Guffa
Guffa, could I say that PreviousPage property is used just to collect date about the opener page, but not to update it?You said, use Javascript to do this, could you explain this more?
Ahmed
Yes, PreviousPage creates a new Page object that has data like ViewState and Form data, but it has no relation to the page displayed in the browser. I added some Javascript examples to the post.
Guffa
+1  A: 

You can submit the parent page back to the server using javascript. You can use window.opener function in the javascript to access the parent page.

AvidProgrammer
Agreed, window.opener will give you a reference to the window that opened the modal/pop-up page. You can then call the JS functions on the parent page from the new window, or update controls directly.
Zhaph - Ben Duguid