Click here to Skip to main content
Email Password   helpLost your password?

Introduction

I am building a content management intranet for my company. The website is based on DotNetNuke, and uses the excellent FreeTextBox control in order to enter HTML into the articles. One of the best features of FreeTextBox is that you can easily add your own buttons and functionality to the control. For instance, the built-in function for adding images didn't meet my needs. My images are stored in SQL server, and require a custom src property in order to retrieve the image. No problem - I added a new button to the control, and built a small aspx page that opens in a modal (popup) window. The popup window allows the user to choose an image to insert, or upload a new image to be inserted. But that's where my problems began.

The Problem

If you've never tried to run an aspx page in a modal window before, then I've probably already lost your attention. But if you have, then you've most likely run into a rather odd problem. Just opening and running an aspx page in a modal window works fine, but if you need to do anything that causes a postback, a funny thing happens. The page opens up in a new window. Worse yet, the new window that opens doesn't have any of the data that you just submitted. The whole thing is a total wash. And JavaScript isn't terribly helpful. What to do?

Enter the IFrame

The trick to solving this problem is to wrap the aspx page in a "doorway" page. That is, you make another page that contains an <IFrame> tag with its source page set to your aspx page. The aspx page then behaves normally within the given frame. Here is an example:

<iframe src="Pages/multiforms.aspx" 
  name="embeddedFrame" width="100%" height="100%" />

Great! Ok, so chances are that at this point you are good to go. But there is one problem left - what if you (like I) needed to pass a parameter to the aspx page? In my example above, I needed to pass the article number of the page I was working on, so that the page I was calling would know which images to display. When calling the aspx page, I would do something like this:

http://www.myweb.com/selectimage.aspx?article=12345

But how do pass the parameters from the host page to the IFrame? Well, as the old saying goes, "You can't get there from here". Or can you?

The Solution

Enter the Literal control. That's the little friend that saves the day in this case. Here is how it works. First, create your doorway page (an aspx page) and drop a Literal control on it.

 ...
<form id="Form1" method="post" runat="server">
   <asp:Literal id="Literal1" runat="server"></asp:Literal>
</form>
 ...

In the code behind (or in the script section), load up the literal control with the IFrame tag, along with the parameters you need to pass:

Private Sub Page_Load(ByVal sender As System.Object, _
      ByVal e As System.EventArgs) Handles MyBase.Load
    Dim myURL As String = Request.Url.ToString() 'Get the URL

    'Does the URL contain parameters?

    Dim ParamStart As Integer = myURL.IndexOf("?") 
    'If the URL has parameters, then get them. If not, return a blank string 

    Dim Params As String = IIf(ParamStart > 0, _
      myURL.Substring(ParamStart, myURL.Length - ParamStart), String.Empty)
    If (Request.Params("Page") Is Nothing) _
              Or (Request.Params("Page") = "") Then
        'No page was specified to load in the IFrame, so let the user know

        Literal1.Text = "Error: No page was specified in the parameters."
    Else
        'Return the IFrame, and add the parameters 

        'to the called (src) web page

        Literal1.Text = "<IFRAME NAME='embeddedFrame'" & _ 
          " WIDTH='100%' HEIGHT='100%' SRC='" & _
          Request.Params("Page") & Params & "' />"
    End If
End Sub

The code above is pretty short and well documented, but here it is in a nutshell. We grab the URL passed to the "doorway" page. The "Page" parameter contains the name of the aspx page we wish to load into the IFrame. If there are any additional parameters, we get those and store them in a string called Params. Then, using the Literal control, we dynamically create an IFrame tag. The trick here is, now we can create the IFrame with a src value that contains not only the name of the aspx page we want to load in the IFrame, but we can also add the passed parameters to that page. Cool.

Calling The Page

Now that we have our doorway page, we easily call the aspx page needed, and pass it the necessary parameters, all in one shot. In the example above, I was attempting to call the selectimage.aspx page and pass it an article number. Now, in order to make that work, I do this:

http://www.myweb.com/doorway.aspx?Page=selectimage.aspx&Article=12345

Where To Go From Here

That's pretty much it, although there is room for tweaking left, depending on how thorough you'd like to be. For example, you could easily turn this code into a simple control that could be dropped on a page, or even turn it into a base page to be inherited from. Now that you know the trick, all of these things are rather simple to do, and I leave those options to you to explore in more depth. If you are concerned about passing query strings in plain text as above, there was an excellent article on using secure query strings here.

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralThanks!
rax_s
10:31 21 Nov '08  
Useful tip.

Thanks!
GeneralPassing Values
motasem111
4:16 4 Aug '08  
Hi;

I need to know how to pass values between pages in ASP.Net when using one of the Navigator Tools

BR,
QuestionCustomise IFrame src
zarana shah
22:56 30 Jul '08  
Hi
i am facing the same problem which you mention here, i have to download inside the page of the website. i am passing username and password with the page link but i could not reach up to that page. i can see the login page of that site. when i run prepared url (which i have passed in src of IFrame) in browser than i can reach that page but not using IFrame.

if you have any solution then please reply me.

for ex. http://192.168.1.1/test/userinfo.aspc?username=aaa&pwd=aaa
i have to reach above url but when i pass this url to src property i will get http://192.168.1.1/test/login.aspx

Thanks
Zarana Shah.
Questionhi
bunny.varun
0:43 20 Apr '08  
hello

How can i set the login page as the default page in the browser. if the user writes the path for another page then he is redirected to the login page. how can i do that??
please help

Thank you
GeneralUse IFrame Control Attributes to set src
pmannino
11:58 28 Nov '07  
You can set the IFrame src attribute directly, without resorting to using the asp:literal control, as follows: embeddedFrame.Attributes("src")=Request.Params("Page") & Params
GeneralPlacing more than one iframe
cmrhema
22:31 24 Aug '07  



Please Help
cmrhema
Hi,
I have designed a html table control in asp.net.
On one side of the columns I have hyperlink labels
1.Register
2. Change Password
3.dfdf
4.etc.

I have merged the cells of column no 2
I place an iframe in column 2
Now when I click register I want to the link to the respective iframe(and other iframes should not be visible) and so on for others.
I have designed an iframe,it(the iframe) is occupies the full page(merged columns).
Now I do not have space to design another iframe.
So i have to place so naturally I will place it above the iframe1.
This is ok. But I cannot make the layout static.
And if i use static the second iframe is placed below the first iframe.


"width: 4410px; height: 5px"> <asp:HyperLink ID="HyperLink2" runat="server" ForeColor="Black" Style="position: static" NavigateUrl="Home.aspx" Target="Home">Home "2" rowspan="20">
<iframe id="Home" src ="Home.aspx" name="Home" scrolling="auto"style="position: absolute; height: 432px; width: 713px; z-index: 100; left: 220px; top: 111px;"></iframe>
GeneralIFrame in ASP.NET
The Knowledge
3:55 25 Jul '07  
Hello Everyone,

Can anybody let me know wht features are provided by "iframe" control
How great it is in using to dynamic work



Thnx in Advance
GeneralUsing this inside DNN to embed ASP.NET E-mail
Kashar
6:53 20 Jul '07  
Greetings,

Is there any effective way to pass a SMTP server data to a embeded control inside a I-frame?
GeneralRe: Using this inside DNN to embed ASP.NET E-mail
Todd Davis
8:17 20 Jul '07  
Personally I'd setup a web service and have the embedded control respond to that. Have the hosting page pass the data to the web service instead trying to pass it as a parameter through to the iframe page.

-Todd Davis (toddhd@gmail.com)

QuestionGetting Parameters from an IFrame
estrga
5:29 18 Jul '07  
I'm looking for help on Getting parameters data from an IFrame.

I need my corporate web Header to be the same for all the VB.NET projects. I need to use iFrames to put the header on each page.

In the header there are some Links that opens on the body, How can I pass the actions and parameters from the iFrame (header) to the main page?

TIA

Gabriel Estrada

AnswerRe: Getting Parameters from an IFrame
Todd Davis
5:44 18 Jul '07  
First, I have to remark that I've never heard of a web header being placed in an IFRAME, and it doesn't sound like you are taking the right approach to what you are doing. Shouldn't it just be in a FRAME, as opposed to an IFRAME?

Anyway, assuming you have a reason to do things that way, you are going to have a tough time accomplishing this I think. At the end of the day, an IFRAME is essentially a "browser within a browser", so the page it is looking at is unaware of the hosting page.

If you needed for the body to interact with the header, that would be one thing - you could do an ajax call to a webservice and pull the content back that you need. But since you are clicking on something in the header (which is a seperate page unaware of the host), the only way I can think of is to have the header page "push" some response out that the hosting page and monitor and respond to (think RSS feed). And that's not a great solution because the hosting page would to be constantly hammering away at the header page in order to get the updates in a timely fashion.

Can't say I've ever tried it, and maybe there is something akin to a reverse-ajax call that would pull this off, but I stick by my original statement that putting a header page in an IFRAME is probably a Bad Idea(tm) on all accounts.

Best of luck



-Todd Davis (toddhd@gmail.com)

GeneralRe: Getting Parameters from an IFrame
estrga
6:00 18 Jul '07  
Well...

I'm using VB.net/ASP.net in VS 2003.

I need to copy/duplicate the header control (.ascx) and embed it in each aspx. That's why I'm thinking in iFrames, and left only one header.ascx (or header.aspx) in a common folder and access it from every page.

Also I thought in the Push issue but I can't figure how to do it yet.

Thanks


Gabriel Estrada
GeneralLiteral Control
pganathe
21:25 3 Apr '07  
Hi Todd Davis,
This is a one of the very good example to solve that postback,big window problem.
Similarly i had one more problem, new page have a TextBox and a Button.
The user has to enter the text in that and then click the button(server control).

private void Button_clicked(object sender, CommandEventArgs e)
{
//Some Business Logic code.
Close the page
}

How can i close the page(pop-up one)in server side click event after executing business logic code.




Prashanth Kumar G.
Software Engineer
Bangalore

GeneralRe: Literal Control
parama dharmika
5:01 15 May '07  
You can use javascript,
place a label on your page whereever you may choose Big Grin , simply visible false then. create a javascript function to close the pop up window, and then place the text with the function of javascript that you just have made.

happy coding to all ...Smile




GeneralRe: Literal Control
pganathe
20:39 15 May '07  
Hi parama dharmika,
Thank you very much for the solution.But i am not allowed to use javascript,
in server side coding only i need to do this. Is there any way to close the page
by server side code.

Prashanth Kumar G.
Software Engineer
Mauritius

Questionhow can set the height of ifram
21:53 16 Feb '07  
Does anyway to Set the iframe's Height 100%.
i need to create dynamicaly 'n' no of Chart Control. the page open in iframe how can i maange iframe's height base on no of charts loaded.

case is i have Default.aspx page. that contains usercontrols, each usercontrol contains' iframe src of chart.aspx.
in chart.aspx dynamically load usercontrol's which use to create Chart object.

the Decision of how meany charts are loaded in is Chart.aspx.
but the height of iframe's need to set in default page.

how can i set the height of iframe

Mian
GeneralThanks
.NETWannabe
6:03 25 Oct '06  
This solved a problem for me!Smile

.Net Wannabe

GeneralHow to make this ATLAS enabled?
Dsypher
9:08 18 Jul '06  
Hi,

I was wondering if we can perform a postback with the help of the Atlas UpdatePanel control and pass the parameters to the Iframe using the literal. Lets say I have two buttons on my page called "Guides" and "Contact Me". If I click on the "Guides" button, my Guides.aspx page would be loaded into the IFrame and so on.

Any sorta help would be greatly appreciated.

--------------------------------------------------------
Be nice to geeks. You might end up working for one. Wink
Generalbase target
shubie
16:13 29 Sep '05  
How about just putting the basetarget property to _self in the head element of the page you are posting back in a modal, this prevents the page in the modal window opening in a new window.
GeneralQuestion about Passing parameters to an ASP.NET page running in an IFRAME
sdubin
8:38 16 May '05  
Hello,

I tried using this technique, but I'm having trouble getting it to work. I have created the doorway page which I'm calling "main_page.aspx". I initially load it with another page ("report_page.aspx") which has some text boxes and a submit button for running a report. From this page, I have a hyperlink to another page (selection_criteria.aspx) which has more selection criteria options, and this page loads in the doorway page as well. Selection_criteria.aspx has a button to return to the doorway page and report_page.aspx: onclick="document.location.href = 'Main_Page.aspx?Page=report_page.aspx'" .

The problem is that if I enter data into the text boxes in report_page.aspx, then click on the "selection_criteria" link, make some additional selections and then click on the button to return to report_page.aspx, it loads it in an "inner frame" with empty text boxes. In other words, I can see the border of report_page.aspx when it first loaded but now it is loading a blank report_page.aspx inside of this (i.e., one border inside the other border).

The goal of course is to go back to the original report.aspx with the text boxes still filled and then be able to submit the form after having captured the additional selection criteria.

Has anyone else experienced this problem?

Thanks in advance for any help.


GeneralCan we access session
skjagini
8:08 13 Dec '04  
Hi,

Can we access session from Doorway Page.
If not is there any other solution for this.

Thanks

General¿ question ?
ING. ANGEL URBANO
12:41 14 Oct '04  
I have a page aspx, within her this a IFRAME with diverse controls, in the page I have a processing button. The question is like I can accede from this button to the data contained in the controls in the page loaded in the IFRAME, you can you help me

KINDLY: ANGEL
GeneralPassing Parameters.
Vinu
11:40 6 Oct '04  
Hi All

I have a Main.aspx which has a iframe htmlcontrol on it, First time it load I set the src to login.aspx. Once the login formality is completed i would like to set it someother page say master.aspx. I am not able to reference this htmlcontrol. I need to pass a parameter to the IFrame Src property.

I am a Software Engineer Interested to Dwell around interesting Concepts in C#
Regards
vinu
Generalgood, but how to solve this?
yuipcheng
1:04 28 Aug '04  
if the page contains multiple iframes, you can't make the click event in iframeA to fire the form submit in iframeB.

why do you need this?

sometimes, you want users to click on a link from one iframe, but updates the content in another iframe.

rayc
GeneralGreat tip
thebigo
20:51 3 Jul '04  
Thanks Big Grin


Last Updated 10 Feb 2004 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010