Solved

How to attach a src to a iframe

Posted on 2006-11-16
8
449 Views
Last Modified: 2008-02-01
I have a iFrame control on an ASP.NET aspx page.
I need to add a src value to the control. Currently it is blank

 <iframe id="printFrame"  runat="server"  style="width:0px;height:0px" src="" ></iframe>

The src is a pdf file that is created dynamically with the Session.SessionId appended.
Example if the Session.SessionID is "zjr5j5mw1ti1ym45o2ilkc45", then the file will be stored on the server as

zjr5j5mw1ti1ym45o2ilkc45.pdf in some location under the application.

Example ./PDFFiles/zjr5j5mw1ti1ym45o2ilkc45.pdf

Can I do something like this and point the src to some location of the file

<iframe id="printFrame"  runat="server"  style="width:0px;height:0px" src='<%#Concat(./PDFFiles/Session.SessionID.Value,.pdf %>) ></iframe>

0
Comment
Question by:countrymeister
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 10

Expert Comment

by:dennis_maeder
ID: 17958515
You can dynamically (or programatically) change the source of an iframe by reassigning the src.
e.g.
<iframe id='myframe' src='test1.html' width=100 height=100></iframe>
<button onclick='document.getElementById("myframe").src="test2.pdf"'>?</button>
D
0
 
LVL 1

Author Comment

by:countrymeister
ID: 17958625
Well, maybe my question is very generic, but I have tried my best to explain what needs to be done.
I very well know how to do the simple stuff as adding a basic src, what I need is to attach a Session.SessionID. alonwith the path name of he location of the src.
I am not a javscript/html expert and need to know if the following will work

Can I do something like this and point the src to some location of the file

<iframe id="printFrame"  runat="server"  style="width:0px;height:0px" src='<%#Concat(./PDFFiles/Session.SessionID.Value,.pdf %>) ></iframe>
0
 
LVL 10

Expert Comment

by:dennis_maeder
ID: 17959302
yes. But you will need to "quote" your path. Which scripting language is that? Syntax may vary.
<%#Concat("./PDFFiles/Session.SessionID.Value",".pdf" %>)
in PHP it would be somewhat different.
<?php echo $_SERVER["DOCUMENT_ROOT"]."/PDFFiles/Session.SessionID.Value".".pdf"; ?>

D
0
Industry Leaders: 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!

 
LVL 1

Author Comment

by:countrymeister
ID: 17959496
I need the solution in ASP.NET
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 17960762
don't know what exactly your Concat() returns as result, but you src= attribute most likely need to look like:
   src='<%#Concat(./PDFFiles/Session.SessionID.Value,.pdf) %>'
or
   src="<%#Concat(./PDFFiles/Session.SessionID.Value,.pdf) %>"
0
 
LVL 10

Accepted Solution

by:
dennis_maeder earned 250 total points
ID: 17961157
And there was me thinking this was a javascript TA!
I think your form should be

<iframe id="printFrame"   style="width:0px;height:0px" src="./PDFFiles/<%# runat='server' response.write (Session.SessionID.Value) %>.pdf "></iframe>

runat is ASP not HTML so should be inside the asp tag
For the rest its pure HTML with a little ASP injected to rovide the session ID
response.write dumps it into the html stream
D
0
 
LVL 1

Author Comment

by:countrymeister
ID: 17965067
Dennis,

It gives me an error stating - Too many characters in character literal, when I do a build.

So I did the following
 <iframe id="printFrame"   runat="server" style="width:0px;height:0px" src="~/PDFFiles/<%#Response.Write(Session.SessionID.Value) %>.pdf"> ></iframe>

I believe with ASP.NET 2.0 you can add a runat="server" for an HTML tag.

Thanks for your help
0
 
LVL 10

Expert Comment

by:dennis_maeder
ID: 17965773
countrymeister,
I am glad you sorted out the runat and that things are working now.
D
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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

732 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