Initiating a PostBack on a main window from a popup window

  • Thread starter Thread starter Jay
  • Start date Start date
J

Jay

I have a situation where the user clicks on a button in a
DataGrid to launch a popup window via javascript. In the
popup window the user does some things that result in
changes to the underlying database the DataGrid is using
as a data source. When the popup window is closed I want
to refresh the main window -- i.e., cause a postback to
happen.

Is this possible?

From a user-interface perspective the popup window works
very nice. I know that I could perform the same funtion
in the main window but that would be messy.

Jay
 
If you get the window.opener object (also a window) you can use the
window.location.reload before you close the popup window.
 
If the grid on main window is just populated when the page loads, you just
call opener.location.reload() (javascript call) on pop-up and cause it to
reload the main page.

However, if it needs more work, i.e a postback like some button would have
caused it (say Button) and an event to handle, you could have a hidden
button control on main window:

<asp:Button ID="btnHidden" runat="server" />

and then an associated javascript function for it (also on main window)

function myPostBack()
{
<%=Page.GetPostBackEventReference(btnHidden,'')%>
}

This causes a postback event to be raised in behalf of the Button, when
myPostBAck is called. You could then call this on the pop-up window by:

opener.myPostBack();

and it causes the main window to be posted as if btnHidden would have been
clicked. So to handle this click you need to handle btnHidden's Click event.
of course, if you already have a Button (or other control) that does this,
you could cause the postback on behalf of it as well.
 
You may also just be able to just call the javascript postback that asp.net
creates using
__doPostBack("yourobjectname","") within your own javascript.
 
Definately, but only when there is at least one control at the Page that
requires this JavaScript to exist. A call to Page.GetPostBackEventReference
ensures that __doPostBack declaration is outputted (that's what the control
needing this declaration calls)
 
Back
Top