.NET Framework Class Library
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)
Syntax

Visual Basic (Declaration)
Public Property EnablePageMethods As Boolean
Visual Basic (Usage)
Dim instance As ScriptManager
Dim value As Boolean

value = instance.EnablePageMethods

instance.EnablePageMethods = value
C#
public bool EnablePageMethods { get; set; }
Visual C++
public:
property bool EnablePageMethods {
    bool get ();
    void set (bool value);
}
JScript
public function get EnablePageMethods () : boolean
public function set EnablePageMethods (value : boolean)
ASP.NET
<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.
Remarks

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.

Platforms

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.
Version Information

.NET Framework

Supported in: 3.5
See Also

Reference

Tags :


Community Content

AbdElRaheim
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();
}
}


Page view tracker