The Z-man Blogeth

I think, therefore I get a headache.
posts - 19, comments - 0, trackbacks - 33

My Links

News

Twitter












Archives

Post Categories

Blogs I Know

Information

  • Day of .Net May 5, 2007 - I'll be there!

Tech Tips: Calling a function on your main page from an IFrame

This one had me stumped for a while, turns out it was extremely simple and I just wanted to share.  Here's the setup:

<iframe id="Iframe1" frameborder="1" marginwidth="0" marginheight="0" width="745" scrolling="no" height="445" style="position:absolute;top:30px;left:5px;background-color:White;z-index:1000;visibility:hidden;" src="somepage.aspx"></iframe>

In the somepage.aspx I had a datalist with a SELECT command argument which updated an object on the server, then on the OnClientClick attribute I wanted to run a javascript function on the main page.

<asp:Imagebutton ID="iThumb" runat="server" OnClientClick="SomeFunctionOnParentPage();" CommandName="SELECT" CommandArgument='0' ImageUrl='ImageThumb.aspx' />

I was trying which way to go up the heirarchy tree to find my function. document.parent, document.parent.frameset, etc.  It turns out I was thinking about it all wrong, I needed to think relative to the IFrame.  I just needed to put parent in front of the function name.

OnClientClick="parent.SomeFunctionOnParentPage();"

I struggled with this one a bit, so I figured I'd post it to save someone else the same grief.

Scott Zischerk
Ann Arbor .Net Developers Member

Print | posted on Thursday, January 04, 2007 4:39 PM | Filed Under [ VB.NET Javascript ]

Feedback

No comments posted yet.

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 8 and 1 and type the answer here:

Powered by: