开发者

how to call a pagemethod in a user control using jquery?

I have a user control having a pagemethod开发者_Go百科.

I want to call this pagemethod from my page using jquery's ajax() method?

How can I do that?

Thanks,

Syd


You 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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜