HTML and IFRAME widget for Dropthings

I made two new widgets for Dropthings - one is an HTML widget, that allows you to put any HTML content inside a widget and the other one is an IFRAME widget that allows you to host an IFRAME to any URL. You can see example of these widgets from http://dropthings.omaralzabir.com

You can write any HTML and Script on the HTML Widget and build your own widget at run time. You can put Video, Audio, Picture or even ActiveX components right on the widget. An example of HTML widget is the NatGeo widget:

image image

This is made of HTML Widget where I have just added some widget snippet that I took from ClearSpring.

The IFRAME widget is also very useful. IFRAME widget hosts an IFRAME pointing to the URL you specify in the settings. Using this widget, you can include any widget from widget providers like Labpixies, ClearSpring, Google Widgets and so on. For instance, I have built three widgets from Labpixies - Stock, Sports and Travelocity widget using the IFRAME widget. The only thing I need to specify in order to bring this widgets is to provide the URL of the widgets that you can find from the widget snippet provided on their website.

image image image

HTML Widget

The HTML widget basically collects HTML snippet in a text box and then renders the HTML output inside a Literal control. The UI consists of only a text box, a button and a literal control.

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="HtmlWidget.ascx.cs" Inherits="Widgets_HtmlWidget" %>
<asp:Panel ID="SettingsPanel" runat="server" Visible="false">
HTML: <br />
<asp:TextBox ID="HtmltextBox" runat="server" Width="300" Height="200" MaxLength="2000" TextMode="MultiLine" />
<asp:Button ID="SaveSettings" runat="server" OnClick="SaveSettings_Clicked" Text="Save" />
</asp:Panel>
<asp:Literal ID="Output" runat="server" />

On the server side, there's basically the OnPreRender function that does the HTML rendering. Other code snippets are standard formalities for a widget in Dropthings.

public partial class Widgets_HtmlWidget : System.Web.UI.UserControl, IWidget
{
private IWidgetHost _Host;

private XElement _State;
private XElement State
{
get
{
string state = this._Host.GetState();
if (string.IsNullOrEmpty(state))
state = "<state></state>";
if (_State == null) _State = XElement.Parse(state);
return _State;
}
}

protected void Page_Load(object sender, EventArgs e)
{

}

void IWidget.Init(IWidgetHost host)
{
this._Host = host;
}

void IWidget.ShowSettings()
{
this.HtmltextBox.Text = this.State.Value;
SettingsPanel.Visible = true;
}
void IWidget.HideSettings()
{
SettingsPanel.Visible = false;
}
void IWidget.Minimized()
{
}
void IWidget.Maximized()
{
}
void IWidget.Closed()
{
}

private void SaveState()
{
var xml = this.State.Xml();
this._Host.SaveState(xml);
}

protected void SaveSettings_Clicked(object sender, EventArgs e)
{
this.State.RemoveAll();
this.State.Add(new XCData(this.HtmltextBox.Text));

this.SaveState();
}

protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);

this.Output.Text = (this.State.FirstNode as XCData ?? new XCData("")).Value;
}
}

There you have it, an HTML widget that can take any HTML and render it on the UI. 

IFRAME Widget

Just like the HTML widget, IFRAME widget also has a simple URL text box and it renders an <iframe> tag with the url entered in the URL text box.

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="IFrameWidget.ascx.cs" Inherits="Widgets_IFrameWidget" %>
<asp:Panel ID="SettingsPanel" runat="server" Visible="false">
URL: <asp:TextBox ID="UrlTextBox" runat="server" /><br />
Width: <asp:TextBox ID="WidthTextBox" runat="server" /><br />
Height: <asp:TextBox ID="HeightTextBox" runat="server" /><br />
Scrollbar: <asp:CheckBox ID="ScrollCheckBox" runat="server" Checked="false" />
<asp:Button ID="SaveSettings" runat="server" OnClick="SaveSettings_Clicked" Text="Save" />
</asp:Panel>

<iframe src="<%= Url %>" width="<%= Width %>" height="<%= Height %>" frameborder="0" scrolling="<%=Scrollbar ? "yes":"no"%>" allowtransparency="true" >
Sorry your browser does not support IFRAME
</iframe>

Here the ascx renders an <iframe> tag using the URL, Width, Height values.

The code for the widget is nothing but standard formalities for widget to store the properties.

public partial class Widgets_IFrameWidget : System.Web.UI.UserControl, IWidget
{
private IWidgetHost _Host;

private XElement _State;
private XElement State
{
get
{
string state = this._Host.GetState();
if (string.IsNullOrEmpty(state))
state = "<state><url>http://www.labpixies.com/campaigns/notes/notes.html</url><width>300</width><height>200</height><scroll>false</scroll></state>";
if (_State == null) _State = XElement.Parse(state);
return _State;
}
}

public bool Scrollbar
{
get { return bool.Parse((State.Element("scroll") ?? new XElement("scroll", "false")).Value); }
set
{
if (State.Element("scroll") != null) State.Element("scroll").Value = value.ToString();
else State.Add(new XElement("scroll", value.ToString()));
}
}

public string Url
{
get { return (State.Element("url") ?? new XElement("url", "")).Value; }
set { State.Element("url").Value = value; }
}

public string Width
{
get { return (State.Element("width") ?? new XElement("width", "300")).Value; }
set { State.Element("width").Value = value; }
}

public string Height
{
get { return (State.Element("height") ?? new XElement("height", "200")).Value; }
set { State.Element("height").Value = value; }
}

protected void Page_Load(object sender, EventArgs e)
{

}

void IWidget.Init(IWidgetHost host)
{
this._Host = host;
}

void IWidget.ShowSettings()
{
UrlTextBox.Text = this.Url;
WidthTextBox.Text = this.Width;
HeightTextBox.Text = this.Height;
ScrollCheckBox.Checked = this.Scrollbar;

SettingsPanel.Visible = true;
}
void IWidget.HideSettings()
{
SettingsPanel.Visible = false;
}
void IWidget.Minimized()
{
}
void IWidget.Maximized()
{
}
void IWidget.Closed()
{
}

private void SaveState()
{
var xml = this.State.Xml();
this._Host.SaveState(xml);
}

protected void SaveSettings_Clicked(object sender, EventArgs e)
{
this.Url = UrlTextBox.Text;
this.Width = WidthTextBox.Text;
this.Height = HeightTextBox.Text;
this.Scrollbar = ScrollCheckBox.Checked;

this.SaveState();
}

}

Hosting dropthings in a Virtual Private Server (VPS)

I recently moved www.dropthings.com from a shared hosting to a VPS. The main reason is the ability to configure IIS the way I want. On a shared hosting, you cannot tweak IIS settings, nor can you turn on IIS gzip compression. Without these tweaking, it's not possible to make a high performance website. So, I bought a VPS from vpsland.com and hosted the website their. Enjoy the new website with lots of new widget, 3x faster performance and the new Live Search on the top right corner.

Published Sat, Apr 5 2008 0:42 by omar
Filed under: ,

Comments

# re: HTML and IFRAME widget for Dropthings

Saturday, April 05, 2008 9:36 PM by rcancel

I have my site hosted by vpsland.com, but sometimes I experience a huge response time ~ 20 seconds. Can you please tell about your experience with them. Thanks

# re: HTML and IFRAME widget for Dropthings

Sunday, April 06, 2008 9:51 AM by omar

Hi rcancel,

This generally happens when the site has been inactive for quite some time and app pool has shutdown. So, first hit wakes up the app pool and take takes quite some time.

But if this is not the case and you sometimes get slow response in the middle of using the site, then you are probably on a heavily loaded physical server where your virtuall server instance is located. Problem with VPS is that you are at the mercy of all other customers on that physical box. If someone has a pretty bad site or someone is doing heavy disk intensive work, it will slow down your VPS.

# re: HTML and IFRAME widget for Dropthings

Wednesday, April 09, 2008 5:57 AM by Thameem

Sir,

  You have any example for load a rss feed to widgets,I am try to do like that ,Please explain me,

I need your help

# re: HTML and IFRAME widget for Dropthings

Thursday, April 24, 2008 6:40 AM by Thameem

I got  load a rss feed to widgets from dropthings , please have you explain how to put pagination in that rss widget

# re: HTML and IFRAME widget for Dropthings

Tuesday, June 03, 2008 9:20 PM by Dale

I went out and looked at VPSLand and I must say I am surprised at how inexpensive they are, I have never seen a plan where you can get an RDP session for $20/mo. Which plan is dropthings using? I am trying to gauge how large a server I need to get to do the work I have now. Thanks for your input and the fantastic framework. I have been very impressed with what you have done with dropthings. Thankfully the book is fairly easy to follow and not filled with a lot of useless fluff that some of the other authors put in just to get a large amount of pages.

# re: HTML and IFRAME widget for Dropthings

Wednesday, June 04, 2008 1:00 AM by omar

I use the Business plan $35/mo. Good enough for me.

For a production environment, I suggest you take two VPS - one for Web and one for DB. Although the communication between Web and DB will happen over the public address, but you can use Firewall to allow only your Web server IP to access the DB server.

Make sure both VPS have at least 1024 RAM

# re: HTML and IFRAME widget for Dropthings

Thursday, July 03, 2008 5:27 AM by Rainmaker

Sir, Ask a question! Why sometimes IFrame will override the DeletePageConfirmPopup? How to solve this problem? thanks!

# re: HTML and IFRAME widget for Dropthings

Monday, July 07, 2008 12:23 AM by Rainmaker

Sir, If Iframe's page is .mht, the ConfirmPopup can't cover it!

# re: Live Search in Dropthings

Tuesday, July 08, 2008 8:44 AM by armache

Dear Al Zabir,

I am reading the book "Building a Web 2.0 Portal with ASP.NET 3.5". The Live Search doesn't work neither in book example nor on dropthings.com. What is the reason?

# re: IFRAME widget for Dropthings

Thursday, July 17, 2008 4:15 AM by Ash

Hi

I wanted to know if I can create my own widget and embed or host that widget in the third party sites like google.

Please let  me know how to do that.

# Single Sign On Authentication

Friday, August 15, 2008 12:45 PM by Raj

Hi Omar:

I am wondering how we can get access to secure resource in another website for each widget , that way users dont have to login for each widget. Do you have any ideas or suggestions on how to proceed with that problem in single sign on authentication style ?

Thanks!!

# Data Display Problem

Friday, March 06, 2009 12:59 AM by Nazeer Rahman

Sir

I have Downloaded the Code.But I am not able to see any data in the widget.Please help me where I need  to do the modification

Thanks in Advance

Nazeer Rahman

# re: HTML and IFRAME widget for Dropthings

Saturday, March 28, 2009 2:03 PM by Jovanoski

Hi,

I have tried to implement the widgets on a web site, and everything seems fine,except the HTML widget.It seems that it won't save the entered HTML and after that all the widgets are "broken", you can't close them or edit them. do you have an answer for this problem?

Regards  

# re: HTML and IFRAME widget for Dropthings

Saturday, November 14, 2009 8:30 AM by Chương

Hi

I wonder if your website can allow to administrator log in and manage widget or not??

# re: Changing With and Hight

Monday, November 23, 2009 4:25 PM by Abrahrami

Hi Omar,

How do you change the widget's width/height when the user click on expand?

Regards

Abahrami

Leave a Comment

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