Solved

How to attach a src to a iframe

Posted on 2006-11-16
8
435 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
  • 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
 
LVL 1

Author Comment

by:countrymeister
ID: 17959496
I need the solution in ASP.NET
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now