views:

333

answers:

4

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.

+1  A: 

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

SLaks
+1  A: 

Hi,

The article of How to make cross page Postback Or visit this one http://www.devx.com/dotnet/Article/33835/0/page/2

How to cause a page to postback from a frame at :

http://forums.asp.net/p/1187580/2030635.aspx

Angkor Wat
You're misunderstanding the question. He's trying to cause the outer frame, which has already been loaded, to do a normal postback.
SLaks
Ok, I just added another reference for him to look at.
Angkor Wat
A: 

Is it possible to do a postback programatically from the code behind of the iframe to the parent page?

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

but that will only do a postback for the iframe i think.

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

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

Ramesh
+1  A: 

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();
bechbd