I have a aspx page, in that page i have an Iframe. In the Iframe i do some stuff in code behind and when it is done I would like to do a postback from the aspx.
In other words, Is it possible to do a postback programatically from the code behind of the iframe to the parent page?
I think a postback can be done using "ClientScript.GetPostBackClientHyperlink(New Control(), String.Empty)" but that will only do a postback for the iframe i think.
I have done this in two different ways:
1) Have a hidden button on the parent page. When you need it to post back you register some javascript that causes a click of that button:
Parent HTML:
<asp:Button ID="Button1" runat="server" Text="" Style="background-color: Transparent;
color: inherit; border-style: none;" />
Iframe Code Behind:
ClientScript.RegisterStartupScript(Me.GetType(), "RefreshParent", "<script type='text/javascript'>var btn = window.parent.document.getElementById('Button1');if (btn) btn.click();</script>")
2) From code behind register a client script that calls the post back on the form in the parent page. The JS would be something like:
window.parent.document.forms[0].submit();
Assuming that the pages are in the same domain, you can emit Javascript that triggers a postback in the outer page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With