Solved

How to attach a src to a iframe

Posted on 2006-11-16
8
442 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

823 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