Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
ScriptManager Class
 EnablePageMethods Property

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.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)
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.

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
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
This property does not do exactly what it says      AbdElRaheim   |   Edit   |   Show History

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

Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker