?
Solved

Change the Src of an iFrame from another Page

Posted on 2006-05-07
6
Medium Priority
?
2,275 Views
Last Modified: 2007-12-19
Hi All,
   
    I wonder if what I want to do is possible. On My main page I create TWO iFrames Side by Side based on a Session Variable:

Response.Write("<iframe scrolling=no width=256 height=1024 frameborder=no bordercolor=silver id='iframemenu' src='" + Session["PageMenu"].ToString() + "'></iframe>");


Response.Write("<iframe scrolling=no width=256 height=1024 frameborder=no bordercolor=silver id='iframetarget' src='" + Session["PageURL"].ToString() + "'></iframe>");

  So there are two pages side by side, one is a menu and the other is the target for the menu items.

 I am using an ASP:Menu in the Menu page and in the the Callback

 protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)

 I want to change the src of the OTHER iframe  

 PSEUDOCODE  iframe["iframetarget"].src = "xcxxx"

If I can't do that I simply want to refresh the Main page that creates BOTH the iframes that way I can repopulate the two ifrrames using session variables.

 PSEDOCODE    thepagewhocreatedme.Refresh  or  URLThatWasTypedintpTheBrwwser.Refresh or RefreshBrowserPages

 Spent waay toooo long trying to find out how to do this

Thanks

Bill







0
Comment
Question by:williamcampbell
  • 3
  • 3
6 Comments
 
LVL 1

Expert Comment

by:FirePits
ID: 16626395
Are you saying that you want to change the src of one iFrame from within the other iFrame? If so, then yes you can do this. I have done it before. If I remember correctly you need to reference the parent, and then the parent (you call it Main page) is able to change the source of the other iFrame. Something like, parent.iFrame2.src = 'whateverSrc.aspx'. One thing, I think I did that with Javascript, so you might need to call a Javascript function to change the src of the other frame, at least with the way I did it.
0
 
LVL 12

Author Comment

by:williamcampbell
ID: 16631162
FP Yes I am trying to update the iFrames src from another iFrame.

  I think your suggestion is correct however I don't know how to:

 1) Get the Parent Page in C#
 2) Call a Javascript Function from C#

  You said you had done this before..can you dig up some source code :)

B
0
 
LVL 1

Accepted Solution

by:
FirePits earned 750 total points
ID: 16632552
Let me look around, I'll post in a little while....
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Expert Comment

by:FirePits
ID: 16632868
Here's an example:

You have 'Main.html' and the two iFrame pages, 'iFrame1.html' & 'iFrame2.html'

1) Main.html: load the iFrames like usual

<html>

<frameset cols="50%,50%">
<frame src="iFrame1.html" name="iFrame1">
<frame src="iFrame2.html" name="iFrame2">
</frameset>

</html>

2) iFrame1: Your navigation page

You will need to include the following Javascript in the <head> of the navigation page:

<script language="JavaScript"><!--

Function changeFrame2Src(location) {
this.parent.iFrame2.src = location; }

//--></script>


3) Your asp.net menu control will look something like the following:

  <asp:Menu runat="server">
<Items>
<asp:MenuItem navigateUrl="javascript:changeFrame2Src(iFrame3.html)">Change target to iFrame3</asp:MenuItem>
<asp:MenuItem navigateUrl="javascript:changeFrame2Src(iFrame4.html)">Change target to iFrame4</asp:MenuItem>
</Items>
  </asp:Menu>


*Keep in mind that I haven't tested the code!*

Another way to do it is to put the changeiFrameSrc function in the <head> of Main.html and call 'parent.changeiFrameSrc()'. You would then have to change the line of the function to: 'iFrame2.src = location;'

Hope this works for you!

(I think they are talking about your same problem here: http://www.dynamicdrive.com/forums/archive/index.php/t-3088.html)
0
 
LVL 12

Author Comment

by:williamcampbell
ID: 16636552

  Fp,

   Well I tried your suggestion and various incantations of it to no avail.

// On the main page
Response.Write("<iframe scrolling=no width=100% height=1024 frameborder=no bordercolor=silver id='iframetarget' src='" + Session["PageURL"].ToString() + "'></iframe>");

I'm not using a frameset I am dynamicaly creating the iframe and as far as i can ascertain there is no way to access the iframe from another child (
this.parent.frames["iframetarget"].src = null. Your link suggests calling a function in the parent that can access the iframe that may work.

However I reverted to my plan B refreshing the parent form and passing a session variable back. This way I can handle things from code behind which is what I really want. After much hair pulling....

    protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
    {
        this.Session["PageURL"] = e.Item.PopOutImageUrl.ToString();  // I store the src url in this parameter so sue me ;)
        string l_script = "";
        l_script = "@SCRIPT>parent.document.forms['FrmMain'].submit();self.close()@/SCRIPT>";
        Page.RegisterClientScriptBlock("CloseChild", l_script.Replace("@", "<"));
        // By registering this script the parent page is refreshed and this page closes (Assuming you main page form is frmmain)
        // the parent picks up the session variable and dynamically creates the iframe on refresh
    }

I hope others find this useful.

Doc


0
 
LVL 12

Author Comment

by:williamcampbell
ID: 16636562
Fp passed on da points to you for the help

Regards

Doc

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

830 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