UFrame: goodness of UpdatePanel and IFRAME combined

UFrame combines the goodness of UpdatePanel and IFRAME in a cross browser and cross platform solution. It allows a DIV to behave like an IFRAME loading content from any page either static or dynamic. It can load pages having both inline and external Javascript and CSS, just like an IFRAME. But unlike IFRAME, it loads the content within the main document and you can put any number of UFrame on your page without slowing down the browser. It supports ASP.NET postback nicely and you can have DataGrid or any other complex ASP.NET control within a UFrame. UFrame works perfectly with ASP.NET MVC making it an replacement for UpdatePanel. Best of all, UFrame is implemented 100% in Javascript making it a cross platform solution. As a result, you can use UFrame on ASP.NET, PHP, JSP or any other platform.

<div class="UFrame" id="UFrame1" src="SomePage.aspx?ID=UFrame1" >
  <p>This should get replaced with content from Somepage.aspx</p>
</div>

Response from SomePage.aspx is rendered directly inside the UFrame. Here you see two UFrame's are used to load the same SomePage.aspx as if they are loaded inside IFRAME. Another UFrame is used to load AnotherPage.aspx that shows photos from Flickr.

image

See it in action!

You can test UFrame from:

What is UFrame?

UFrame can load and host a page (ASP.NET, PHP or regular html) inside a DIV. Unlike IFRAME which loads the content inside a browser frame that has no relation with the main document, UFrame loads the content within the same document. Thus all the Javascripts, CSS on the main document flows through the loaded content. It's just like UpdatePanel with IFRAME's src attribute.

The above UFrames are declared like this:

<div id="UFrame1" src="SomePage.aspx" >
    <p>This should get replaced with content from Somepage.aspx</p>
</div>

The features of UFrame are:

  • You can build regular ASP.NET/PHP/JSP/HTML page and make them behave as if they are fully AJAX enabled! Simple regular postback will work as if it's an UpdatePanel, or simple hyperlinks will behave as if content is being loaded using AJAX.
  • Load any URL inside a DIV. It can be a PHP, ASP.NET, JSP or regular HTML page.
  • Just like IFRAME, you can set src property of DIVs and they are converted to UFrames when UFrame library loads.
  • Unlike IFRAME, it loads the content within the main document. So, main document's CSS and Javascripts are available to the loaded content.
  • It allows you to build parts of a page as multiple fully independent pages.
  • Each page is built as standalone page. You can build, test and debug each small page independently and put them together on the main page using UFrames.
  • It loads and executes both inline and external scripts from loaded page. You can also render different scripts during UFrame postback.
  • All external scripts are loaded before the body content is set. And all inline scripts are executed when both external scripts and body has been loaded. This way the inline scripts execute when the body content is already available.
  • It loads both inline and external CSS.
  • It handles duplicates nicely. It does not load the same external Javascript or CSS twice.

Download the code

You can download latest version of UFrame along with the VS 2005 and VS 2008 (MVC) example projects from CodePlex:

www.codeplex.com/uframe

Please go to the "Source Code" tab for the latest version. You are invited to join the project and improve it or fix bugs.

Read the article about UFrame

I have published an article about UFrame at CodeProject:

http://www.codeproject.com/KB/aspnet/uframe.aspx

The article explains in details how the UFrame is built. Be prepared for a big dose of Javascript code.

If you find UFrame or the article useful, please vote for me at CodeProject.

kick it on DotNetKicks.com
Published Sat, May 24 2008 20:31 by omar
Filed under: , ,

Comments

# re: UFrame: goodness of UpdatePanel and IFRAME combined

Monday, May 26, 2008 11:12 AM by Matt

Omar,

That is such a great idea! I really hate using IFRAMES and this seems like the perfect solution to get around them. Does the use of a div tag to hold the content allow it to dynamically resize the height of the container based on the content? That is something I can't stand with iframes, vertical scroll bars. Thanks!

# re: UFrame: goodness of UpdatePanel and IFRAME combined

Monday, May 26, 2008 11:47 AM by omar

The container DIV automatically resizes according to content width and height.

# re: UFrame: goodness of UpdatePanel and IFRAME combined

Monday, May 26, 2008 12:10 PM by Mattt

Omar,

One more question as I'm starting to try out the UFrame. Is there a way to make the frame content keep its own app root directory? I'm trying to use the UFrame to house an image gallery application i'm developing which relies on the ~/ virtual directory to remain in tact, but I also want the main sites master page and controls to stay as they are while housing the application in the frame.

So, for example, the Uframe is in the /root/pictures/Default.aspx file with a src="/root/gallery/Default.aspx". When I click on a link inside the frame that is app relative, the directory is still seen as /root/pictures which causes the gallery app to fail. Any way around that? Thanks again!

# re: UFrame: goodness of UpdatePanel and IFRAME combined

Monday, May 26, 2008 12:28 PM by omar

As the content is embedded inside the main document, all paths are calculated from the path of the main document, not from where the UFRame loads the file.

The only workaround to this problem is to parse all <img> tag's src attribute and stylesheet url(...) and do the path translation based on the path of the UFrame src.

# re: UFrame: goodness of UpdatePanel and IFRAME combined

Monday, May 26, 2008 6:04 PM by Umut

Omar,

I think this is great work.

I have a question, how uFrame differs from the "load function" of jQuery (or similar functions of JS Frameworks) which lets you load any content (URL, file, etc..) inside a DIV?

Or uFrame is a similar, but sure, works without any JS framework?

# re: UFrame: goodness of UpdatePanel and IFRAME combined

Tuesday, May 27, 2008 4:29 AM by does UFrame can be a container of an UserControl

if UFrame can be a container of an UserControl. then the web page can be combined by some user control. So we can build B/S application same as build C/S application by SCSF.

# re: UFrame: goodness of UpdatePanel and IFRAME combined

Friday, May 30, 2008 10:01 PM by justink

is it affected by cross-domain limitations?  Can a page on abc.com use a uframe to load a page from xyz.com?

# re: UFrame: goodness of UpdatePanel and IFRAME combined

Thursday, June 05, 2008 3:06 AM by Nick

Brilliant control. Will drop things we converted to use UFrames?

# re: UFrame: goodness of UpdatePanel and IFRAME combined

Friday, June 06, 2008 4:06 AM by Rainmaker

1.Your UFrame.js's License is GPL License. May i use it in business? thanks.

2.Javascript can't cross-domain?

# re: UFrame: goodness of UpdatePanel and IFRAME combined

Friday, June 06, 2008 4:45 AM by omar

1. You can. Please email with your business description and I will send you a commercial license.

2. Without a proxy, no.

# re: UFrame: goodness of UpdatePanel and IFRAME combined

Wednesday, June 11, 2008 5:54 AM by Rainmaker

We try to use UFrame in Dropthings's Widget.

we hope UFrame can pass some AP's Parameters into UFrame Body, if UFrame body have some url link.

So... UFrame.js License ......

# re: UFrame: goodness of UpdatePanel and IFRAME combined

Sunday, June 15, 2008 7:13 PM by Martillo

Hi Omar,

Thank you for your generosity in sharing UFrame with the development community.

I'm working on a commercial app right now (at least, if we're lucky it will be commercial...) and am just starting to evaluate UFrame to see if it will work for us.

Regarding the issue of licensing, I noticed that on the CodePlex site the UFrame license is a Microsoft Public License (Ms-PL), which appears to permit the use of UFrame in commercial applications.

# re: UFrame: goodness of UpdatePanel and IFRAME combined

Tuesday, June 24, 2008 11:27 AM by Rainmaker

Hi Martillo:

Yes, But why Uframe.js's License is GPL "License"?

That mean we can't use Uframe.js?

Or we can use all source in commercial?

# re: UFrame: goodness of UpdatePanel and IFRAME combined

Wednesday, June 25, 2008 1:12 AM by omar

UFrame is free for commercial use. Just keep the license intact.

I committed new version with modified license. Thanks for notifying.

# re: UFrame: goodness of UpdatePanel and IFRAME combined

Tuesday, July 01, 2008 12:45 AM by Rainmaker

It's possible to use UFrame in Dropthings?

# re: UFrame: goodness of UpdatePanel and IFRAME combined

Friday, July 25, 2008 9:39 PM by michael

Where is the code for uframe?

# re: UFrame: goodness of UpdatePanel and IFRAME combined

Friday, August 08, 2008 3:37 AM by William Melvin

The UFreame idea looks like a great one.  Congratulations!.

I have one question, I am currently working on a project were I need to host a component on a web page that maintains a connection via TCP back to a host application.  This TCP link would be passing messages back and forth, sometimes pushing messages to the client without notice.  I currently have this functionality encapsulated in an ACTIVEX component (eeekkkkkkkk!!!).  I am trying to replace that with something more elegant.  When messages come back from the host system, I would need to reload some part of the ASPX pages outside of the UFrame. Could UFrame help in this type of component hosting?

Thanks,

William

# re: UFrame: goodness of UpdatePanel and IFRAME combined

Wednesday, August 20, 2008 4:57 AM by Craig Norris

Hi Omar,

This is a great tool. I've one hassle. Using ASP.Net 3.5 I would like to use either an UpdateProgress or Ajax Control Toolkit UpdatePanelAnimationExtender to show something while the uframe is loading a different page (using javascript to call navigate).

Do I need to give them a specific name or use a specific reference within them?

Thanks in advance

# re: UFrame: goodness of UpdatePanel and IFRAME combined

Thursday, September 04, 2008 12:04 AM by Alaa Shaheen

This is an awesome work. We are definitely going to implement it in our site!

# re: UFrame: goodness of UpdatePanel and IFRAME combined

Monday, September 08, 2008 3:11 AM by Steve Lechowicz

This looks like just what I have been looking for. Thanks for your generosity. I do have a query. Is the UFrame compatible with Telerik controls for ASP.NET AJAX?

# re: UFrame: goodness of UpdatePanel and IFRAME combined

Monday, September 08, 2008 4:14 AM by omar

I haven't tried myself, but I heard some complex controls like Telerik Grid does not work. Problem with these commercial components are they are too Javascript dependent and they do not perform regular postback. So, it's hard for UFrame to capture their actions and do it the ajax away.

# re: UFrame: goodness of UpdatePanel and IFRAME combined

Tuesday, September 16, 2008 3:35 PM by TML

Hi Omar...excellent concept!!!

Can Uframes be loaded dynamically through JavaScript or does the src attribute need to be set in the markup?

Thanks.

# re: UFrame: goodness of UpdatePanel and IFRAME combined

Saturday, September 20, 2008 6:19 AM by Radhika

Hi Omar ....Great concept

I had small doubt.How can we create UFrame dynamically.

Thanks.

# re: UFrame: goodness of UpdatePanel and IFRAME combined

Saturday, September 20, 2008 11:50 AM by omar

When page loads, UFrame library finds all DIV on the page and then it creates one UFrame per UFrame wannabe div dynamically. So, you can do the same thing to create dynamic uframes.

Here's the code that creates one UFrame per DIV:

initContainers : function()

   {

       $('div[@src]',document).each(function()

       {

           var container = $(this);

           var id = container.attr("id");

           if( null == UFrameManager._uFrames[id] )

           {

               UFrameManager.init({

                   id: id,

               loadFrom: container.attr("src"),

               initialLoad : "GET",

               progressTemplate : container.attr("progressTemplate") || null,

                   showProgress : container.attr("showProgress") || false,

               beforeLoad: function(url,data) { return eval(container.attr("beforeLoad") || "true") },

               afterLoad: function(data, response) { return eval(container.attr("afterLoad") || "true") },

               beforePost: function(url,data) { return eval(container.attr("beforePost") || "true") },

               afterPost: function(data, response) { return eval(container.attr("afterPost") || "true") },

               params : null,

               beforeBodyTemplate : container.attr("beforeBodyTemplate") || null,

               afterBodyTemplate : container.attr("afterBodyTemplate") || null

               });

           }

       });

   }

Basically you take one DIV and call UFrameManager.init(...) and pass the details about the uframe.

Note: most of the parameters are optional. You can just specify null to them. For ex, on progressTemplate, showProgress, beforeLoad etc can be null. However, id, loadFrom, initalLoad is required.

# re: UFrame: goodness of UpdatePanel and IFRAME combined

Tuesday, September 23, 2008 4:19 AM by Radhika

Hi Omar,

Thanks for u r reply.

In my project i need to create multiple uframes dynamically.can u explain me how to create multiple Uframes ?

# Update panel exception

Wednesday, November 05, 2008 8:17 PM by Sergey

Hi Omar,

I am using the uframe in conjuction with an update panel on a the main page (not on the page that's inside the uframe).  Whenever there's a partial postback on the main page, I get this exception:

sys.webforms.pagerequestmanagerservererrorexception: the state information is invalid for this page and might be corrupted

Any ideas?

# re: UFrame: goodness of UpdatePanel and IFRAME combined

Thursday, November 06, 2008 4:00 PM by Roger

codeplex downloads says "no releases" available?

http://www.codeplex.com/UFrame

Is this still available?

# re: UFrame: goodness of UpdatePanel and IFRAME combined

Tuesday, December 16, 2008 8:42 AM by austinHodge

You have to go to "Source Code" and retrieve the JavaScript files.  There is no compiled code to be downloaded.

austinHodge

# re: UFrame: goodness of UpdatePanel and IFRAME combined

Tuesday, December 30, 2008 8:42 AM by khalil

i also getting the "the state information is invalid for this page and might be corrupted" error. anyone fixed it yet ? just a normal page with uframe and a post button

# re: UFrame: goodness of UpdatePanel and IFRAME combined

Friday, January 09, 2009 9:02 AM by Mitch

Hi Omar, awesome idea.

Are u using this control on any of your production applications? I'm concerned about future browser / asp.net version compatibilities. I you are using it in a production app, I know that you will keep it up to date.

Thanks for sharing, I hope you don't think I'm dissing your project in any way, just wondering if it is going to have a great mind behind it, updating it etc. (certainly not me).

Mitch

# re: UFrame: goodness of UpdatePanel and IFRAME combined

Saturday, February 14, 2009 1:00 AM by BG

Does UFrame support external site URL loading in a website?

# re: UFrame: goodness of UpdatePanel and IFRAME combined

Thursday, March 05, 2009 11:31 AM by Geoffrey Spencer

I have a series of ImageButtons at the top of the page that will change the src of the div that is below these buttons. How do I change the src path when I click one of these buttons?

Thanks

# re: UFrame: goodness of UpdatePanel and IFRAME combined

Wednesday, March 11, 2009 10:31 AM by jason

I see the code you posted above, but i'm still confused about how to dynamically set the src from an asp.net page. If i set the src manually uframe works great, but from my OnLoad() function in asp.net how can i set src. Can you provide an example. It would really help me out a lot. thanks, great idea.

# re: UFrame: goodness of UpdatePanel and IFRAME combined

Tuesday, April 21, 2009 12:49 PM by Shankar

Hi Omar, The control is really useful, but i have one issue. When i try to post the page (Eg. Server side button click event), am getting the error "System.Web.HttpException: The state information is invalid for this page and might be corrupted". I have downloaded the latest source code from codeplex site but still i am getting the same. I dont have any subdirectory in my website. All my aspx page reside in the root folder

Leave a Comment

(required) 
(required) 
(optional)
(required)