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.
Assembly: System.Web.Extensions (in System.Web.Extensions.dll)
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.
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();
}
}
- 12/4/2008
- AbdElRaheim
- 12/4/2008
- AbdElRaheim