1

In a child popup window I have the following button.

<asp:Button Style="width: 100%;" ID="Button2" runat="server" OnClientClick="RefreshParent()"
 OnClick="Button1_Click" Text="Select Study" />

The OnClick function allows the user to select a study which changes the entire site's content, this part works fine, thus isn't listed.

The OnClientClick function should refresh the parent page, but doesn't cause the client data to update unless I manually refresh the page (F5). Here is the RefreshParent code.

<script type="text/javascript">
    function RefreshParent() {
        window.opener.document.reload()
        window.close();
    }
</script>

In the function I have also tried:

window.opener.document.reload(true)

and

window.opener.document.href("home.aspx")

Nothing worked. Is there a method that will cause a server postback from a child window with either the code behind or javascript? Thanks.

todd.pund
  • 689
  • 2
  • 11
  • 36
  • Have you tried `__doPostBack()` ? See: http://stackoverflow.com/questions/1305954/asp-net-postback-with-javascript – David Feb 07 '13 at 21:20

2 Answers2

1

have you tried :

<script type="text/javascript">
    function RefreshParent() {
        window.opener.location.reload();
        window.close();
    }
</script>

You might also want to return false in the OnClientClick (not really a matter as you are closing window)

jbl
  • 15,179
  • 3
  • 34
  • 101
  • Ack! I'm sorry, I meant to type location in all of those. window.opener.document.reload() doesn't even work. I guess I went into autopilot while typing this question. So yes, the answer to your question is yes, I've tried that. – todd.pund Feb 07 '13 at 22:07
0

I think what is happening is that your reload of the parent page is done before your popup window OnClick method has executed. In order to have your reload script execute after the post back is finished, I suggest you wrap your script in a placeholder which is displayed after postback:

<asp:placeholder id="refresh_script" visible="false" runat="server">
  <script type="text/javascript">
    window.opener.location.reload();
    window.close();
  </script>
</asp:placeholder>

In your OnClick handler:

refresh_script.Visible = true;

Remove the OnClientClick handler from your button.

Ray
  • 21,485
  • 5
  • 48
  • 64