0

The data being return in the error function is saying: Unknown web method IncrementTable(pageNumber). Parameter name: methodName. I'm sure that I've made a small mistake somewhere, but hoping a second pair of eyes can help me find it. :)

My .aspx page looks like this:

<%@ Page Title="TouchStoneTV" Language="VB" AspCompat="True" AutoEventWireup="True" Debug="True" EnableEventValidation="True" ValidateRequest="False" Trace="False" EnableViewState="True" %>

<%@ Import Namespace="System.Web.Services" %>
<%@ Import Namespace="System.Web.Script.Services" %>

<WebMethod()> _
Public Shared Function IncrementTable '(ByVal PageNumber As Integer)

Dim PageNumber As Integer = 1
For x As Integer = 0 To Math.Ceiling(RowsPerPage/CellsPerRow)

    Dim r As TableRow = New TableRow
    'If (x Mod CellsPerRow) = 0 Then r = New TableRow
    r.Attributes.Add("style","text-align:center;height:200px;width:50%;")

    Dim c1, c2 As New TableCell
    c1.Attributes.Add("style","border:1px solid #000;")
    c2.Attributes.Add("style","border:1px solid #000;")
    c1.Controls.Add(New LiteralControl(PageNumber.ToString & "a : " & x.ToString))
    c2.Controls.Add(New LiteralControl(PageNumber.ToString & "b : " & x.ToString))
    r.Cells.Add(c1)
    r.Cells.Add(c2)

    MainContentTable.Rows.Add(r)

Next x

Return "test"

End Function

And the javascript look like this:

<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript">

var pageNumber = 1;
//var webMethodUrl = '<%=ResolveUrl("~/Mobile.aspx/IncrementTable(pageNumber)") %>'; //alert(webMethodUrl); //this gets a 404-not found error
var webMethodUrl = 'Mobile.aspx/IncrementTable(pageNumber)'; 

$(document).ready(function () {
    $(window).scroll(function () {
        // Get the current vertical position of the scrollbar.  If it's equal to the height of the document minus the 
        // window height then go get some more data
        if ($(window).scrollTop() == $(document).height() - $(window).height()) {
            // Increment page number and set up the parameters
            pageNumber += 1;
            var params = "{'pageNumber': " + pageNumber + "}";

            // Async post back to the BindDataAsync code behind web method
            $.ajax({
                type: "POST",
                url: webMethodUrl,
                data: params,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                error: function (data) {alert('error: ' + data);},
                success: function (data) {alert('success');
                    //if (data != "") {
                        // Take the results from the web service method and append them to the table
                    //    $('#ProductsTable').append(data.d);
                    //}
                }
            });
        }
    });
});

</script>

2 Answers 2

1

The method is configured for invocation using httpget but you are using POST method to invoke in javascript.

<WebMethod()> _
<ScriptMethod(UseHttpGet:=True, ResponseFormat:=ResponseFormat.Json)> _
Public Shared Sub IncrementTable(ByVal PageNumber As Integer)
  'code
End Sub

Just remove UseHttpGet:=True and it should fix your issue. Or change jquery ajax code to use GET request and pass parameter as querystring

Sign up to request clarification or add additional context in comments.

7 Comments

I was wondering about that. I changed that line to: <ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _. And...same error.
Try removing the ScriptMethod attribute from your method and keep the WebMethod as it is
I take it back - you gave me a clue...I'm updating the issue. I had to: 1) remove the UseHttpGet, and 2) turns out I was refreshing the page to test it and the URL had some bad characters at the end.
Now it goes to success, but the table (in the code I showed above) doesn't refresh. Any ideas?
(btw, I'll mark your response correct, if you submit it as an answer)
|
0

Remove the parameter:

var webMethodUrl = 'Mobile.aspx/IncrementTable';

1 Comment

Then I must do this: url: 'Mobile.aspx/IncrementTable', And...same error.

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.