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

8.1k Views Asked by At

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?

2

There are 2 best solutions below

2
On BEST ANSWER

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 
1
On

Check and make sure you didn't name your ScriptManager control "ScriptManager". If you did, the compiler will try to use that control rather than calling the static GetCurrent method on the ScriptManager class.