First published on TECHNET on Jun 04, 2013
I worked on a case where the problem was that PageMethods won’t execute from within a SharePoint 2013 application page (page deployed to the _layouts folder). To replicate the problem, I had a custom master page deployed through a VS 2012 solution with the following definition within the <body/> element.
And I had my TestMethod defined in my application page as shown below.
Notice the ‘onclick’ attribute added to the server-side button control in the Page_Load event. The idea is, when this page is loaded and the button is clicked, we call the “CallMe()” function defined in the master page. And this client-side function will call the server-side TestMethod method by virtue of having PageMethods enabled. But this is what happens in SharePoint 2013.
The page loads.
Click the button.
There are multiple ways to fix it.
1. Deactivate “Following Content” feature. Not a good one, but if this feature is not being used (which is highly unlikely), then simply deactivating it resolves this error.
2. Modify the “Following Content” feature. Change the 2 functions defined in the ScriptBlock of <CustomAction/> element to be named functions instead of anonymous. Deactivate/Uninstall “Following Content” feature. Install/Activate “Following Content” feature. THIS OF COURSE, IS UNSUPPORTED .
3. Override the Render method in the application page and inject a semi-colon character. Below is the modified application page code.
Once you deploy this solution, browse to the application page and watch the scripts pushed using IE Developer Tools, you’ll see this.
Notice that “;” character after the PageMethods declaration just before the anonymous functions from “Following Content” feature starts. Now, when the application page is browsed.
And the button is clicked.
The first alert is displayed and when you click OK, you’ll see the second alert as well.
That resolves this issue. Hope this post was helpful.
Cross post from http://blogs.msdn.com/sridhara
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.