-[Danny Chen]- Blog of an ASP.NET QA tester

Tips and info about Site Navigation, ImageMap, Menu and other cool ASP.NET v2.0 features.

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 + "]";

        }
    }
}
 
 
 

 
Posted: Mar 02 2006, 09:40 AM by dannychen | with 1 comment(s)
Filed under:

Comments

Khurram shahzad said:

I have tried to add this code on page init functions but i am not seeing same behaviour. what could be the reason. i simply copy pasted the oninit code in page oninit funciton to see if i can get same result on page..

Please elaborate. .Thanks..

# October 8, 2007 9:28 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)