Custom Control Challenge - Entry #2
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;
namespace PageLoadingDisplayControls {
[ToolboxData("<{0}:PageLoadingDisplay runat=server></{0}:PageLoadingDisplayControl>")]
[Designer(typeof(PageLoadingDisplayDesigner))]
public class PageLoadingDisplay : WebControl {
protected override void OnInit(EventArgs e) {
Page.Response.Buffer = true;
base.OnInit(e);
Page.Response.Write(@"
<![CDATA[
Pad the buffer otherwise IE does not render on flush
Padding not required for Firefox
]]>
<div id=""imgLoading"">
<img src=""images/loading.gif"" alt=""Loading"" />
</div>");
Page.Response.Flush();
Page.ClientScript.RegisterStartupScript(this.GetType(),
"foo",
"document.getElementById('imgLoading').style.display='none';",
true);
}
}
}
Control Designer:
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.Design.WebControls;
using System.Web.UI.WebControls;
using System.Reflection;
namespace PageLoadingDisplayControls {
public class PageLoadingDisplayDesigner : ControlDesigner {
public override string GetDesignTimeHtml() {
Control control = base.ViewControl;
return "[PageLoadingDisplay : " + control.ID + "]";
}
}
}