1

What the heck am I doing wrong here?

I get this error: [ArgumentException: Unknown web method Test2. Parameter name: methodName] System.Web.Script.Services.WebServiceData.GetMethodData(String methodName) +540418 System.Web.Handlers.ScriptModule.OnPostAcquireRequestState(Object sender, EventArgs eventArgs) +213 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +148 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

<script type="text/javascript" src="/Library/JS/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        setTimeout(function () {  

            $.ajax({
                type: "POST",
                url: "_debug.aspx/Test2",
                data: "{ param: 555 }",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                    console.log(msg);
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    console.log(jqXHR);
                    console.log(textStatus);
                    console.log(errorThrown);
                }
            });

        }, 1000);

    });

</script>


Imports System.Web.Services
Imports System.Web.Script.Services

Partial Class debug
Inherits Page 
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not IsPostBack Then

        End If
    End Sub

    <WebMethod(EnableSession:=True)> _
    <ScriptMethod(UseHttpGet:=True)> _
    Public Function Test(ByVal param As String) As String
        Return "testing " & HttpContext.Current.Session("UserID")
    End Function

    <WebMethod(EnableSession:=True)> _
    <ScriptMethod()> _
    Public Function Test2(ByVal param As String) As String
        Return "testing " & HttpContext.Current.Session("UserID")
    End Function
End Class 

1 Answer 1

3

The methods need to be Shared:

<WebMethod(EnableSession:=True)> _
<ScriptMethod(UseHttpGet:=True)> _
Public Shared Function Test(ByVal param As String) As String
    Return "testing " & HttpContext.Current.Session("UserID")
End Function

<WebMethod(EnableSession:=True)> _
<ScriptMethod()> _
Public Shared Function Test2(ByVal param As String) As String
   Return "testing " & HttpContext.Current.Session("UserID")
End Function

and also check your script manager allows page methods:

<asp:ScriptManager ID="ScriptManager1" 
EnablePageMethods="true" 
runat="server" />
Sign up to request clarification or add additional context in comments.

2 Comments

I read that ScriptManager was not required and I was looking for a way to do it without ScriptManager. Is this possible?
Tried it without scriptmanager. Your solution worked! MUCH THANKS

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.