views:

647

answers:

4

I have a page with a GridView on it that launches a popup, using Javascript. The user then selects an item, that updates the data connected to the GridView and closes the popup.

How do I refresh the first (ie the Calling page) so that I can refresh the data shown in my Gridview?

+1  A: 

Try this inside your popup:

<script>
window.opener.location.reload()
</script>

That should refresh the page that opened the pop-up

TonyB
This causes the following:---------------------------Microsoft Internet Explorer---------------------------The page cannot be refreshed without resending the information.Click Retry to send the information again,or click Cancel to return to the page that you were trying to view.
David Smit
A: 

If you simply need to trigger a postback on the calling page, this should work:

<script>
window.parent.document.forms[0].submit();
</script>

By explicitly submitting the form, you avoid the warning that appears if you just refresh the calling page.

If you need to trigger an OnSelectedIndexChanged event on the GridView during the postback, then things are a bit fiddlier, but you should be able to do it by calling window.parent.document.__doPostBack() with suitable arguments.

stevemegson
A: 

Here is the Solution:

Dim CloseScript As String = "<script language='javascript'>function closeWindow(){ window.opener.document.forms[0].submit();window.close();}closeWindow();</script>"

In .NET 2.0 you have to add this to the page to register above Javascript:

 'register with ClientScript 
    'The RegisterStartupScript method is also slightly different 
    'from ASP.NET 1.x 
    Dim s As Type = Me.[GetType]()
    If Not ClientScript.IsClientScriptBlockRegistered(s, "CloseScript") Then
        ClientScript.RegisterClientScriptBlock(s, "CloseScript", CloseScript)
    End If
David Smit
A: 

Does this avoid the 'page cannot be refreshed' message

window.opener.location = window.opener.location;

(sorry I would have just left a comment on TonyB's post but I don't have enough SO points, so I'm not allowed... :(

Justin