How can I Postback a page inside a iframe from the container page?

Posted on 2004-11-18
Last Modified: 2010-05-18

How can I invoke the postback of a page inside a iframe from its container page?

I've got a iframe inside a .aspx page (main), the iframe loads another .aspx page, the user can do several things in this iframe page like capture data. Now, I want, from a button on the main page, to make the iframe aspx postback.

How can I do that.
Question by:mak730
    LVL 2

    Accepted Solution

    <a href="javascript:document.getElementById('myIFrame').contentWindow.execScript('__doPostBack('ActionPostback','');');">postback my little iframe</a>
    <iframe id="myIFrame" src="mypage.aspx">
    LVL 2

    Expert Comment

    make sure your page mypage registers it's postback script:
    do this by putting


    in the override protected void OnInit(EventArgs e) (this is generated by VS.NET for aspx pages in the "Web Form Designer generated code" region)
    LVL 25

    Expert Comment

    Check out the following article:

    Title: DotNetJunkies :: On-the-Fly Non-Postback .NET Server Validation

    HTH, Nauman.

    Author Comment

    weareu, your code works simply right!

    Thanks a lot

    A couple of questions more:
    1)contentWindow.execScript() works on Netscape, Opera and Firefox also, or just IE?
    2)How, on serverside, do I receive the value of the param: 'ActionPostback' of the __doPostBack('ActionPostback', '')?

    Points are yours
    LVL 2

    Expert Comment

    Yes contentWindow.execScript works on mozilla (dunno about opera or firefox)

    You cannot receive the value in normal ASPX page without alot of hard work... if you need to postback additional values, create a hidden input (that runs server side) runat="server" and before you do the postback script set the value of this hidden input to also postback... remember that the hidden input has to be inside the iframe page for you to retrieve it server-side there. Also remember since it is in the iframe page you need to access it in the same kind of way to set the value so before __doPostBack(... do

    document.getElementById('myIFrame').contentWindow.execScript('document.getElementById(\'hiddenPBvalue\').value = \'postback something\';');

    and then document.getElementById('myIFrame').contentWindow.execScript('__doPostBack('ActionPostback','');');

    when your page posts back the serverside hidden input will contain the value 'postback something'...

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now