0

I'm trying to call a server method from javascript and the call returns the error message "The server method 'IsQueueEmpty' failed." On the server I have:

protected void Page_Load(object sender, EventArgs e) 
{
   (this.Master as MainMaster).ScriptManager.EnablePageMethods = true;
}

[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod(UseHttpGet = true, ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]
public static bool IsQueueEmtpy() 
{
   return true;
}

On the client side I have the following:

<script type="text/javascript">
   function onSuccess(complete) {
      if (!complete) {
         watchQueue();
      }
   }

   function onError(result) {
      alert(result);
   }

   var watchQueue = function () {
      setTimeout(function () {
         PageMethods.IsQueueEmpty(onSuccess, onError);
      }, 2000);
   }

   watchQueue();
</script>

Any suggestions would be greatly appreciated.

adam
  • 502
  • 1
  • 6
  • 17
  • Take a look at this answer... http://stackoverflow.com/a/4558607/3199781 – Anthony Chu Feb 10 '16 at 17:55
  • Add attributes to the method you are calling : [WebMethod] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] public static bool IsQueueEmtpy() – DinoMyte Feb 10 '16 at 18:08
  • I have added the attributes as suggested by @DinoMyte but I am still getting the same error. Now it has a status of 404. – adam Feb 10 '16 at 18:15
  • 404 means method is not found. make sure you are invoking the pagemethod from the same page – DinoMyte Feb 10 '16 at 18:18
  • Looks like I am. The script tag is on the Review.aspx page while the server code posted is on the Review.aspx.cs page. The code behind attribute on the page matches as well. As I dig into the error it says the method was not found or implements IController. Isn't that an MVC interface? Why would that be needed in this circumstance. – adam Feb 10 '16 at 18:31

0 Answers0