How to pass int values to ASP.NET page methods from jQuery?
Asked Answered
S

3

6

I am using ASP.NET page methods with jQuery. Here is my code,

$.ajax({
      type: "POST",
      url: "Default.aspx/GetRecords",
      data: "{}",
      contentType: "application/json; charset=utf-8",
      dataType: "json",

and the ASP.NET page method is,

[WebMethod]
public static string GetRecords(int currentPage,int pagesize)
{
    // my logic here
}

How to pass values for currentPage and pagesize from jQuery?

Saari answered 30/3, 2010 at 4:3 Comment(0)
S
7

I got it working. My data section must be

data: "{'currentPage':1,'pagesize':5}",
Saari answered 30/3, 2010 at 4:24 Comment(0)
P
0

Did you try just:

$.ajax({
    type: "POST",
    url: "Default.aspx/GetRecords",
    data: {"currentPage": 1, "pageSize": 100},
    contentType: "application/json; charset=utf-8",
    dataType: "json",

?

Patriotism answered 30/3, 2010 at 4:12 Comment(1)
@codeka when inspected through firebug it 500 internal server errorSaari
P
0

Try this

$.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        data: "{ currentPage: '" +parseInt( $('#currentpage').val()) + "',pageSize:'"+parseInt( $('#pagesize').val()) +"'}",
        url: "Default.aspx/GetRecords",
        dataType: "json",
        success: function (data) {
                     $("#result").html(data.d);
                 }
        });
Paint answered 4/10, 2011 at 7:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.