Postback programmatically from iframe to parent page

I have an aspx page, on this page I have an iframe. In Iframe, I am doing some things in the code behind and when this is done I would like to do a postback from aspx.

In other words, is it possible to do programmatic postback from the code behind the iframe to the parent page?

I think postback can be done using "ClientScript.GetPostBackClientHyperlink (New Control (), String.Empty)", but this will only do the postback for the iframe, I think.

+3
source share
4 answers

I did this in two different ways:

1) . , , javascript, :

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) script, . JS - :

window.parent.document.forms[0].submit();
+6

, , Javascript, .

+1

iframe ?

Yes. To automatically publish the form from the code behind, you need to register javascript startup, which will submit the form. You can assign a form action to point to the aspx page of the parent.

but this will only do the postback for the iframe, I think.

To make the form fill the parent window instead of the current one, you can add the "_target" attribute to the form and set it to "_parent"

If you want to trigger a postback by simulating a button click, you can do it as SLaks pointed out.

0
source

Source: https://habr.com/ru/post/1736168/


All Articles