Initiating a PostBack on a main window from a popup window

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
 
C

Chris Jackson

If you get the window.opener object (also a window) you can use the
window.location.reload before you close the popup window.
 
T

Teemu Keiski

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.
 
T

Teemu Keiski

Note that for the Button to be hidden, it should have Visible="False" as
well. :)
 
V

vMike

You may also just be able to just call the javascript postback that asp.net
creates using
__doPostBack("yourobjectname","") within your own javascript.
 
T

Teemu Keiski

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)
 
Joined
Sep 21, 2006
Messages
2
Reaction score
0
my pop up needs refresh

hi,

this topic is really really close to what im trying to accomplish, hei, teemu, ive downloaded your sample and follow ur intruction but to no avail. maybe i didnt find a way to apply it to my situation, so here;s my code (in po up)

strItemID = CType(lbtnItemID.Text.Trim(), String)

strJavaScript &= "window.opener.PostBackOnMainPage();" & _
HttpContext.Current.Request.QueryString("objFindItemID") & ".value = '" & _
strItemID.Trim & "';window.close();"
strJavaScript = strJavaScript & "</script" & ">"
Literal1.Text = strJavaScript


if u see the window.opener.PostBackOnMainPage(), i already apply it, but still get errors, pliz help...

thanks and sorry for my poor english
 
Joined
Sep 21, 2006
Messages
2
Reaction score
0
fast solution

okay, ive found another way of doing this, this suits my situation very well, just by adding this line in my window.opener :-

window.opener.document.forms(0).submit();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top