views:

1396

answers:

3

i have iframe inside a page, and this iframe contain a submit button which will do some function.

What i want is: after the iframe submit finish, call the parent page to refresh.

i know how to refresh it:

parent.location.reload();

But i don't know how to do that after submit finish.

A: 

Submitting a form is the FINAL action on the document in the Iframe. Once you submit a form, that page has been "submitted" and is no longer active. If you refresh the parent first, you lose the Iframe. The moment you submit in the Iframe, you can no longer talk to the parent.

You can do one of a few things here:

  • Target the PARENT when you submit the form, then the parent will have whatever you want in a NEW iframe on that page.
  • Have the resulting page in the iframe reload the parent using JavaScript on the result page.
Diodeus
A: 

Use an onload event handler on your iframe. When it fires after the submit, execute your top.location.reload...

// In parent
window.onload = function() {
  document.getElementById("MY_IFRAME").onload = function() {
    top.location.reload();
  }
}
Josh Stodola
A: 

I solved this problem by adding this line of code in the code behind after all my methods finished:

    ScriptManager.RegisterStartupScript(this, typeof(string), "script", 
"<script type=text/javascript>
parent.location.href = parent.location.href;</script>", false);

And the reason i didn't write parent.location.reload() and wrote parent.location.href = parent.location.href is to don't send the data twice to server as i want a new fresh page load.

Amr ElGarhy