How to do a Page PostBack With a Delay

Here's a simple way to delay a Page PostBack.

Add the following code in the Page_Load event:

C#


    protected void Page_Load(object sender, EventArgs e)


    {


        TimeSpan ts = new TimeSpan(0, 0, 0, 5);


        System.Threading.Thread.Sleep(ts);


    }




VB.NET


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)


        Dim ts As New TimeSpan(0, 0, 0, 5)


        System.Threading.Thread.Sleep(ts)


    End Sub





Note: Avoid using this approach too much in a Production environment.

Will you give this article a +1 ? Thanks in advance


About The Author

Suprotim Agarwal
Suprotim Agarwal, ASP.NET Architecture MVP (Microsoft Most Valuable Professional) works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He is the Editor of a Developer Magazine called DNC Magazine. He has also written two EBooks 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook

Follow him on twitter @suprotimagarwal

1 comment:

Dilip Mishra said...

Thanks yaar... got some hint for my query (y)