2

私はこのasp.net関数の値を取得しようとしています:

[ScriptMethod, WebMethod]
public static bool checkRefresh()
{
    return isChanging;
}

PageMethodを使用してjqueryで呼び出すことにより:

var isAllowed = false;
$("#edit").click(function () {
    PageMethods.editFunc();
    PageMethods.checkRefresh(DisplayMyResult);   //this line gives the error, though it's probably because it's first.
});

function DisplayMyResult(ResultString) {
    isAllowed = ResultString;
    if (isAllowed == true || isAllowed == "true") {
        location.reload();
    }
    else {
        PageMethods.checkRefresh(DisplayMyResult);
    }
}

私が(クロムコンソールで)得るエラーは

Uncaught TypeError: Object function () {
PageMethods.initializeBase(this);
this._timeout = 0;
this._userContext = null;
this._succeeded = null;
this._failed = null;
} has no method 'checkRefresh'

なぜ機能しないのかわかりません。誰か助けてもらえますか?

4

1 に答える 1

3

ScriptManagerを使用するのではなく、代わりにjQueryを使用してpageメソッドを呼び出したいと思います。この素晴らしい記事を読んでくださいjQueryを使用してASP.NETAJAXページメソッドを直接呼び出す

  [WebMethod]
  public static string checkRefresh()
  {
    return isChanging;
  }


$.ajax({
  type: "POST",
  url: "PageName.aspx/checkRefresh",
  data: "{}",
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  success: function(msg) {
    // Do something interesting here.
   }
});
于 2012-12-14T05:49:59.860 に答える