65.9K
CodeProject is changing. Read more.
Home

How to Check if the Page was a partial PostBack

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0 vote)

Oct 11, 2013

CPOL
viewsIcon

21231

While developing ASP.NET 2.0 application with AJAX  many times we came across scenarios when we had to know if the call made to the server is

While developing ASP.NET 2.0 application with AJAX many times we came across scenarios when we had to know if the call made to the server is complete postback or partial postback (using update panel)

In ASP.NET 2.0 a property called IsCallBack was exposed for the user to validate this. However it was found that this property is always set to false when used along with ASP.NET AJAX extensions.

In case a partial postback is done using update panel you will find the IsPostBack is always true and IsCallback is always false.

Hence to check whether the page was called using update panel or it was a complete postback we can use the below code.

if (ScriptManager.GetCurrent(this).IsInAsyncPostBack)         
{          
    // Do something only when the page is partially posted back         
}

The ScriptManager.GetCurrent(this).IsInAsyncPostBack returns true when the server side code is invoked using a update panel.

Where this is the instance of the page to which the postback was made.