Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2004-11-18
5
Medium Priority
?
3,373 Views
Last Modified: 2010-05-18
Hi

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.
Thanks
0
Comment
Question by:mak730
  • 3
5 Comments
 
LVL 2

Accepted Solution

by:
weareu earned 2000 total points
ID: 12620169
<a href="javascript:document.getElementById('myIFrame').contentWindow.execScript('__doPostBack('ActionPostback','');');">postback my little iframe</a>
<iframe id="myIFrame" src="mypage.aspx">
0
 
LVL 2

Expert Comment

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

this.Page.GetPostBackEventReference(this);

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)
0
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 12620434
Check out the following article:

Title: DotNetJunkies :: On-the-Fly Non-Postback .NET Server Validation
URL: http://www.dotnetjunkies.com/Article/E02F3646-CB1C-4252-8AEC-5F485E90A231.dcik

HTH, Nauman.
0
 

Author Comment

by:mak730
ID: 12620725
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
0
 
LVL 2

Expert Comment

by:weareu
ID: 12620926
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'...
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses

581 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