LcSalazar LcSalazar - 1 month ago 19
Ajax Question

Page_Load is been fired when WebMethod is called through javascript PageMethods

I have an aspx page. I've added a ScriptManager to it, and set

EnablePageMethods=true
, and created a static method marked as [WebMethod] on the server-side.



I have always worked with WebMethods, and I've never seen this error before.


On javascript, PageMethods is accessible. But when I call my method, the
Page_Load
method is fired, instead of the WebMethod.


I've searched and found other people had this issue as well. But no answers.... Any ideas?

HTML:

<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"></asp:ScriptManager>


JS:

PageMethods.Test()


C#:

[WebMethod]
public static void Test()
{

}

Answer

I discovered that the problem on my case is that I'm using friendly URL's. Since PageMethods references the server-side page by its address, there you have the issue. It's been discussed here, on CodePlex: http://aspnetfriendlyurls.codeplex.com/workitem/3.

Apparently there are workarounds for this, but I ended up making a manual ajax call to a generic handler (.ashx).