Link to home
Start Free TrialLog in
Avatar of countrymeister
countrymeister

asked on

How to attach a src to a iframe

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>

Avatar of Dennis Maeder
Dennis Maeder
Flag of United States of America image

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
Avatar of countrymeister
countrymeister

ASKER

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>
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
I need the solution in ASP.NET
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) %>"
ASKER CERTIFIED SOLUTION
Avatar of Dennis Maeder
Dennis Maeder
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
countrymeister,
I am glad you sorted out the runat and that things are working now.
D