i have a webmethod that call it by jquery ajax .in web method i bind repeater data source to pagedatasourse object but when i run my program if i dont use of static key word webmethode before method name jquery ajax method dose not work properly and its normal because jquery ajax only work with static method and if use static keyword i have this error
Quote:
Object reference not set to an instance of an object....System.NullReferenceException: Object reference not set to an instance of an object
and pagedatasourse fall in exception.i confused.what is solution? thank you very much its my jquery function
<blockquote class="FQ"><div class="FQA">Quote:</div>$(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 behiend
<blockquote class="FQ"><div class="FQA">Quote:</div>
[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();
}