ScriptManager.GetCurrent ( Page ).IsInAsyncPostBack throws an error at runtime

Giuseppe Romagnuolo picture Giuseppe Romagnuolo · Feb 24, 2011 · Viewed 7.6k times · Source

it's a couple of hours that I'm stuck on what apparently seems a very silly problem and I cannot move forward.

Basically if I try to evaluate the following at any of the event handlers of an ASP.NET Web Form Page (ie at Page_Load):

ScriptManager.GetCurrent ( Page ).IsInAsyncPostBack

I always get the following error:

'System.Web.UI.IScriptManager' does not contain a definition for 'GetCurrent' and no extension method 'GetCurrent' accepting a first argument of type 'System.Web.UI.IScriptManager' could be found (are you missing a using directive or an assembly reference?)

However if I evaluate the same in any of the embedded UserControls' events I do get a boolean value returned.

Am I missing something very basic?

Answer

Tim Schmelter picture Tim Schmelter · Mar 30, 2011

Are you using an AjaxControlToolkit-ScriptManager? I had also sometimes problems to debug the IsInAsyncPostBack value.

Change

ScriptManager.GetCurrent(Page).IsInAsyncPostBack

To

AjaxControlToolkit.ToolkitScriptManager.GetCurrent(Page).IsInAsyncPostBack