I have a web method that calls its jquery ajax. In the web method, I bind the data source repeater to the pagedatasourse object, but when I run my program, if I do not use the static webmethode keyword before the jquery ajax method name, the method does not work correctly and if I use the static keyword, I have this error
The reference to the object is not set to the instance of the object .... System.NullReferenceException: the reference to the object is not set to the instance of the object.
and pagedatasourse fall into exception.i confused.What is the solution? Thanks a lot for its jquery function
$(function () { var x = 0; $('.c1').bind('click', function () { counter = counter + 1; $.ajax( { type: "POST", url: "WebForm1.aspx/bringdata", data: { counter: counter }, contentType: "application/json; charset=utf-8", dataType: "json", async: true, cache: false, success: function (ret) { alert("success"); }, error: function (x, e) { alert("error "); } } ); }) $('.c2').bind('click', function () { x = x - 1; }) })
and its code:
[WebMethod] public static void bringdata(int counter){ SqlConnection con = new SqlConnection("data source=.;database=site;integrated security=true;"); int cnt; string sSQL = "Select username ,average,weight,point,password ,kal, Rank() over(order by point desc) as 'ranking' from karbar order by point desc"; SqlCommand cmd = new SqlCommand(sSQL, con); SqlDataAdapter adapt = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); adapt.Fill(ds); cnt=ds.Tables[0].Rows.Count; PagedDataSource pds = new PagedDataSource(); pds.AllowPaging=true; pds.DataSource=ds.Tables[0].DefaultView; pds.PageSize=5; pds.CurrentPageIndex=counter; int vcnt=cnt/pds.PageSize; rptList.DataSource = pds; rptList.DataBind();
}
source share