Monday, October 27, 2008

How to display Progress bar when the first time page load

 

Last time, I introduced the ModalUpdateProgress, which is designed for postback. Then how to show "page loading" when the first time page load,  we need to find another way to achieve it.

We hope the page will not flash too much time. It will be better if the page shows "page loading" with percent progress untill the page loaded and rendered.

 

    protected void Page_Load(object sender, EventArgs e)
    {
        showPageLoad();
        //do somthing


    }
    private void showPageLoad()
    {
        int i=0;
        Response.Write("<div id='divTitle'>Loading(<span id='message'>0%</span>)</div>");
        Response.Flush();
        for(i=5;i<=100;i=i+5)
        {
            System.Threading.Thread.Sleep(200);// any codes can be typed here
            outputflash(i.ToString() + "%");
            Response.Flush();
        }
    }
    private void removePageLoad()
    {
        ScriptManager.RegisterStartupScript(Page, this.GetType(), "deleteLoading", "var d = document.getElementById('divTitle');d.parentNode.removeChild(d);", true);

    }
    private void outputflash(string value)
    {       
      Response.Write("<script type='text/javascript'>document.getElementById('message').innerHTML='" + value + "';</script>");

    }

 

4 comments:

Ranjith Kumar said...

Thank you very much, it helpmed me a lot. Ranjith

Unknown said...

Thank You very Much for your help and code.. This is what I want....

Anonymous said...

Very nice procedure to show percentage....thank you...

Anonymous said...

Thank you