Thursday, June 23, 2011

How to add an event into user control in ASP.NET WebForms?

Reason: Put two user controls in same page, you want call one function in B while one thing happens in A.

Three steps to do that: Define, Raise and Book event. 

Define event in A:
    public delegate void AfterOneTask ();
    public event AfterOneTask AfterOneTaskHandler;

Raise event in A:
    protected void Submit_Click(object sender, EventArgs e)
        if (this. AfterOneTaskHandler!= null) AfterOneTaskHandler();
Book event in B:
    protected void Page_Init(object sender, EventArgs e)
        this.ctlA.AfterOneTaskHandler +=new UserControlA.AfterOneTask(controlb.method1);

What is 8-second rule

 A June 2001 Zona Research report entitled "The Need for Speed II" found that the average web user will wait about eight seconds for a page to download, but that current average download time across backbone connection on most web sites is almost ten seconds.[4]
The 8-second rule is an old (by Internet standards) way of measuring the adequate response time of a webserver through different bandwidth connections. It specified that if the load-time of a web page exceeds eight seconds, users are unlikely to wait, or "stick around", for its completion. In order to increase the "stickiness" of a website, faster ways to deliver the content to the user needed to be devised. These included stripping away unnecessary HTML code and using fewer images.[5]
It is generally believed that this rule no longer applies, since a much higher percentage of Internet users now have broadband available, making almost every website load up much faster, in some cases in less than a second. However, the rule has remained as a rough unit to measure the performance of a webserver.