Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

do postback programatically from iframe to parent page

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.

like image 888
Murre Avatar asked Jul 14 '26 08:07

Murre


2 Answers

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();
like image 103
bechbd Avatar answered Jul 18 '26 12:07

bechbd


Assuming that the pages are in the same domain, you can emit Javascript that triggers a postback in the outer page.

like image 45
SLaks Avatar answered Jul 18 '26 10:07

SLaks