Solved

How to attach a src to a iframe

Posted on 2006-11-16
8
452 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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

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…

707 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