SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to define a WebMethod in one of my Publishing page layouts.

This WebMethod is intended to be called when a user takes a specific action in an Editor Part in a Visual Web Part, however, you can't have a WebMethod in a Server Control or User Control. This web part will only exist on this specific page layout, so I figured the best way would be to implement the WebMethod in the page layout itself. I would then implement a static method in the Editor Part which I would call from the WebMethod.

I implemented this concept successfully in a sample web application then set out to do it in SharePoint. That's when the fun began :)

Set EnablePageMethods on ScriptManager

I started by setting the EnablePageMethods property of the ScriptManager in my master page to true.

Define WebMethod in Page Layout

In the page layout, I define the WebMethod as follows:

public static void MyWebMethod(string someParams)

In the EditorPart, MyWebMethod is implemented as a simple static method:

public static void MyWebMethod(string someParams)
    // do something

I understand that being a static method in the editor part, I won't have access to any of the instance data for it. I'm postponing dealing with that issue until I get the web method working...

Register Scripts in EditorPanel

In the OnInit event of MyEditorPanel, I register the script:

if (!this.Page.ClientScript.IsClientScriptBlockRegistered("myScript"))
        "the contents of my JavaScript script"

Background info on the script: The script runs on the stop event of a jQueryUI Sortable list. It's intended to pass the ordered list (formatted) back to the web method.


I'm able to successfully trigger the script by taking the appropriate action in the MyEditorPanel server control.

I see the request in Fiddler as follows but with a 500 error:


Here's the error:

Unknown web method MyWebMethod.<br>Parameter name: methodName

[ArgumentException: Unknown web method MyWebMethod.
Parameter name: methodName]
   System.Web.Script.Services.WebServiceData.GetMethodData(String methodName) +841944
   System.Web.Handlers.ScriptModule.OnPostAcquireRequestState(Object sender, EventArgs eventArgs) +217
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +80
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +171

When I implemented this in, I could immediately hit the break point in the page. However, in SharePoint, the WebMethod needs to be defined somewhere else. As far as I can tell, that's the only difference between the two implementations.

How have other people approached this?

Thank you


I've abandoned this approach. the necessary plumbing just doesn't seem to be there to use a WebMethod defined in a page layout or master page to communicate back to the web part or editor part.

share|improve this question
What code behind file have you put that C# code in? Is this in a custom page layout you've created? What class did you inherit in the C# codebehind file? – James Love Dec 26 '11 at 19:06
James, yes the C# code is in the code behind of a custom page layout. The class inherits from PublishingLayoutPage. Thanks – George Durzi Dec 26 '11 at 19:07
I should also point out that absolutely nowhere else in the current implementation of the SharePoint object model uses this model at all, as I believe this is incompatible with the way the Publishing Framework works, so is probably not a supported customisation. – James Love Dec 26 '11 at 19:08
Think you can keep the jQuery UI Sortable bit in the Editor Part, but you're gonna need a postback (to sync the web part properties to the personalisation store) to 'update' the visual web part UI. – James Love Dec 26 '11 at 19:15
I have used web methods on an custom application page in SharePoint and that worked perfectly. Haven't tried out on a page layout. – justforkix09 Dec 28 '11 at 17:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.