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.




About The Author

Suprotim Agarwal
Suprotim Agarwal, Developer Technologies MVP (Microsoft Most Valuable Professional) is the founder and contributor for DevCurry, DotNetCurry and SQLServerCurry. He is the Chief Editor of a Developer Magazine called DNC Magazine. He has also authored two Books - 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook.

Follow him on twitter @suprotimagarwal.

1 comment:

Unknown said...

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