0 out of 2 rated this helpful - Rate this topic

ScriptManager.EnablePageMethods Property

Gets or sets a value that indicates whether public static page methods in an ASP.NET page can be called from client script.

Namespace:  System.Web.UI
Assembly:  System.Web.Extensions (in System.Web.Extensions.dll)
public bool EnablePageMethods { get; set; }
<asp:ScriptManager EnablePageMethods="True|False" />

Property Value

Type: System.Boolean
true if static page methods on an ASP.NET page can be called from client script as Web methods; otherwise, false. The default is false.

You can add static page methods to an ASP.NET page and mark them as Web methods. You can then call these methods from script as if they were part of a Web service, but without creating a separate .asmx file. To create Web methods on a page, import the System.Web.Services namespace and add a WebMethodAttribute attribute to each static method that you want to expose. The methods must be marked public.

For more information, see Exposing Web Services to Client Script.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
I am also confused with this property
I agree with AbdELRaheim. I am using a Tooltip server control that can be populated through Page Method. I did not set EnablePageMethods="true", and it still works. I consult the tooltip control supplier and they confirmed me that they did not set it either and it still works, see their Page Method <a href="http://www.menubasic.com/Tooltip/DataSource.aspx">demo</a> at http://www.menubasic.com/Tooltip/DataSource.aspx. If that is the case, why bother us with this useless property?
This property does not do exactly what it says

This property does not do exactly what it says. "Gets or sets a value that indicates whether public static page methods in an ASP.NET page can be called from client script. " is incorrect. You are still able to invoke "pagemethods" even when EnablePageMethods is set to false. The only thing that this property does is determine if a javascript proxy class will be generated for the service. You can still invoke the page methods using xhr or some other js lib ( i am testing with jquery).


I looked in the script manager expecting to see the script manager subscribing to one of the page events to handle the page method requests. Didnt see anything there, instead I found in System.Web.Handlers.ScriptModule. Maybe should change the doc or update the code to check. Looks like it would be a small code change.


private void OnPostAcquireRequestState(object sender, EventArgs eventArgs)
{
HttpApplication application = (HttpApplication)sender;
HttpRequest request = application.Context.Request;
if ((application.Context.Handler is Page) && RestHandlerFactory.IsRestMethodCall(request))
{
// Change to check EnablePageMethods property.
ScriptManager scriptManager = ScriptManager.GetCurrent(application.Context.Handler as Page);
if (scriptManager == null || !scriptManager.EnablePageMethods)
{
return; // Exit and process page as normally
}
// End change

WebServiceData data = WebServiceData.GetWebServiceData(HttpContext.Current, request.FilePath, false, true);
string methodName = request.PathInfo.Substring(1);
WebServiceMethodData methodData = data.GetMethodData(methodName);
RestHandler.ExecuteWebServiceCall(HttpContext.Current, methodData);
application.CompleteRequest();
}
}