Omar AL Zabir blog on ASP.NET Ajax and .NET 3.5

Working hard to enrich millions of peoples' lives

Sponsors

News

I am
Co-Founder and CTO of Pageflakes, acquired by LiveUniverse - founded by MySpace founder.

My Public Page
www.pageflakes.com/omar

View Omar AL Zabir's profile on LinkedIn

Read my blog on:

Omar AL Zabir

www.oazabir.com



Views:

Articles

Open source projects

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

Comments

rachitp said:

Looks pretty cool.

I've used SubModal (sublog.subimage.com/.../subModal)  to do the similar things in the past. Naturally, UFrame does a lot of different things as well. Keep it up!

# May 24, 2008 5:45 PM

mehfuzh said:

Ok, This is really nice! At this point i want to ask, how it will affect the browser performance, if there are 100 of UFrames on the page. So far i can see, UFrame.js does the complex task for finding Divs with src attribute and parsing its content out to make it behave like an updatePanel.

# May 27, 2008 2:09 PM

oazabir said:

Performance will be better than having 100 IFRAMEs on the page.

Use of IFRAME/UFRAME/UpdatePanel needs careful planning as you need to use least amount of these but provide the most value to the user. So, you should always try to provide as much responsive UI as possible with least amount of I/UFrame. I will be surprised to see a real application having more than 20 UFrame offering real value to user.

One such extreme example is Pageflakes.com, where each flake (widget) is already a UFrame. So, we have nice pagecasts like www.pageflakes.com/omar where there are many flakes, which are all individual UFrames (even more complex).

# May 27, 2008 2:19 PM

Wilmot Wustfeltt said:

I am getting a javascript error:

Erro: $("form", container).attr("UFrameID", config.id) is undefined

File: localhost/.../UFrame.js

Linha: 300

What i am doing wrong?

# May 27, 2008 8:36 PM

bduenskie said:

Can the uframe call a page located on another domain?  For instance src="http://www.yahoo.com"?

# May 28, 2008 2:32 PM

oazabir said:

UFrame cannot load pages from external domain unless a proxy is used. So, you will need a content proxy which will fetch content from external domain.

I have an earlier blog post about building such a content proxy.

When you have such a proxy, you just point UFrame to the proxy URL:

<div src="Proxy.ashx?url=http://www.google.com">">http://www.google.com">

...

This will load the initial content. However, form postback will surely fail because a cross domain form post via XMLHTTP is not allowed. So, you will need a proxy to do so.

<div src="Proxy.ashx?url=http://www.google.com" postTo="Proxy.ashx?url=http://www.google.com">">http://www.google.com">

...

</div>

# May 29, 2008 3:02 AM

oazabir said:

Here's the proxy article:

www.codeproject.com/.../ajaxproxy.aspx

In above comment, Proxy.ashx is a fictious proxy that does not job for fetching content from external domain and making HTTP POST to external domain.

# May 29, 2008 3:05 AM

Romi said:

Hi Omar,

Very fantastic your work. I love your PageFlakes.

Could you explain if I can load one usercontrol inside the UFrame, and how to. Same for one Compilled Usercontrol and embeded ascx.? Could you help me with exemples.I'm not dev. Regards  

# June 11, 2008 11:37 AM

Eric said:

I have a few questions: First, I currently use Dreamweaver CS3 as my development tool and have been evaluating Visual Studio 2008 for the past week or so.

1.  i looked at the Uframe, VS 2008 example and noticed the back button on the browser tested in IE 7 does not work as designed. In a typical htm or asp page a developer can make div's act like iframe's or server side includes which load other pages just like Uframe, but the user is still able to use the functionality of the browser.  Are there settings in the Iframe to make this happen? I.e. The back button still works as designed meaning you only have to click one time on the back button to get to a previous page?

2.  How does Google crawl the Uframe? If there is a separate page that get's loaded into a main page or a child page (nested in main) does Google crawl the entire page, including the separate page called by the Uframe as one page (like SSI's)?  Or does Google crawl that nested Uframe pointed page separately like the use of traditional Iframes do?

3.  I have a tab control where i want to call in separate pages into each tab section.  I do not want to load all the Uframe pointed pages when the main or child content pages load.  I want to load the Uframe pointed pages when the user selects a different tab section.  Is there a way to code which Uframe pointed pages get loaded on master or child/master page load? Or is there a way to tell the tab control to only load the default nested page?

4.  I also want to include accordion controls located within each tab, nested Uframe page. Each accordion panel section has several links or buttons which upon clicked increment variables, and refresh a few Uframe pointed pages that are located in the main/nested main document.  Is this possible?

Thanks, Eric

# October 28, 2008 1:12 PM

mark said:

How to update one uframe from another) I created three uframes by div tag that loads aspx pages. Everything works fine in one but i have button on one and need to update other. How to do that?

# January 10, 2009 1:37 PM

srinivas said:

Great Job Omair,

   From past couple of days i was googling for auto adjusting of iframe. there are scripts available to ge the height of iframe content and set the height of iframe. this works great until iframe page height is static. if my iframe's height changes depending of the user selection withing iframe...... i am again lost the height.

     This uframe solved that problem of auto adjusting height with the sub page.

this issue i am facing here is..

i have a  asp.net TreeView . if u select the item from tree view. it loads corresponding page in iframe. now i have replaced iframe with uframe. but i was unable to change the source of the div from javascript.

can u please tell me how to change the uframe divs source from javascript.

thanks in advance

srinivas.

# January 26, 2009 5:58 AM

Ruchir said:

Hello,

    Sir I am using Uframe(Its Great)but i am facing some Problem.i want to load uframe at button click event in cuteEditor.i can see uframe but content in uframe are not visible.can u give some suggestion on this....

# March 20, 2009 1:39 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)