PageMethods worked perfectly when sending a single parameter to a code-behind aspx page. However, I encountered the error "Unknown web method" when attempting to provide two parameters (or an Object other than a String).
The functional code in my aspx page is:
<asp:ScriptManager ID="smAjax" runat="server" EnablePageMethods="true"> </asp:ScriptManager>
and in a js file included:
function AjaxSuccess(results) {
alert("AjaxSuccess: " + results);
}
$(document).ready(function () {
PageMethods.TestAjaxCall("value 1", AjaxSuccess);
}
and in the code-behind:
<ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=False)> _
<WebMethod> _
Public Shared Function TestAjaxCall(ByVal item1 As String) As String
Return item1
End Function
However, making the following adjustments resulted in an exception (System.ArgumentException: Unknown web method TestAjaxCall.): and in an included js file:
function AjaxSuccess(results) {
alert("AjaxSuccess: " + results);
}
$(document).ready(function () {
PageMethods.TestAjaxCall("value 1", "value 2", AjaxSuccess);
}
with the corresponding modification in the code-behind:
<ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=False)> _
<WebMethod> _
Public Shared Function TestAjaxCall(ByVal item1 As String, ByVal item2 As String) As String
Return item1 & ": " & item2
End Function