Click here to Skip to main content
15,884,629 members
Articles / Web Development / ASP.NET

How to Check if the Page was a partial PostBack

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
13 Oct 2013CPOL 20.7K   2   1
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

This articles was originally at wiki.asp.net but has now been given a new home on CodeProject. Editing rights for this article has been set at Bronze or above, so please go in and edit and update this article to keep it fresh and relevant.

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.

C#
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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
The ASP.NET Wiki was started by Scott Hanselman in February of 2008. The idea is that folks spend a lot of time trolling the blogs, googlinglive-searching for answers to common "How To" questions. There's piles of fantastic community-created and MSFT-created content out there, but if it's not found by a search engine and the right combination of keywords, it's often lost.

The ASP.NET Wiki articles moved to CodeProject in October 2013 and will live on, loved, protected and updated by the community.
This is a Collaborative Group

754 members

Comments and Discussions

 
QuestionpartialLoad in js Pin
snir.elgabsi2-Jun-15 1:56
snir.elgabsi2-Jun-15 1:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.