如何使用jquery在用户控件中调用pagemethod?

时间:2011-03-21 12:19:36

标签: jquery asp.net pagemethods

我有一个pagemethod的用户控件   我想使用jquery的ajax()方法从我的页面调用此页面方法?

我该怎么做?

谢谢,
SYD

4 个答案:

答案 0 :(得分:2)

您无法在用户控件上使用PageMethods。他们必须在页面上。

答案 1 :(得分:1)

使用此

$.ajax({
  type: "POST",
  url: "PageName.aspx/MethodName",
  data: "{}",
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  success: function(msg) {
    // Do something interesting here.
  }
});

答案 2 :(得分:1)

$.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
});

答案 3 :(得分:0)

页面方法必须是静态和公共的,它还需要使用WebMethod属性进行修饰,例如:

[WebMethod(EnableSession=true)]
    public static void PageMethod(int Parameter)