how to call a pagemethod in a user control using jquery?
I have a user control having a pagemethod
开发者_Go百科.
ajax()
method?
How can I do that?
Thanks,
SydYou cannot have PageMethods on user controls. They have to be on the page.
Use this
$.ajax({
type: "POST",
url: "PageName.aspx/MethodName",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
// Do something interesting here.
}
});
$.ajax(
{
url: "/Service.asmx/Getuggestions",
type: "POST",
async: false,
contentType: "application/json",
data: "{ text: \"" + request.term + "\", count: 10 }",
success: function (data)
{
var items = new Array();
for (var i = 0; i < data.d; i++)
items[items.length] = { value: data.d[i].Code, label: data.d[i].Text };
response(items);
},
error: HandleAjaxError
});
A page method must be static and public , it also need to be decorated with the WebMethod attribute, for example:
[WebMethod(EnableSession=true)]
public static void PageMethod(int Parameter)
精彩评论