Prachi
Prachi

Reputation:

Ajax function throwing WebServiceFailedException

I am using same asp.net page to edit and add data, only with some fields disabled and enabled accordingly. Now when I call webmethod from the add page, it's working fine, but when I call it from edit page, it is not. Though I am using the same javascript function to call the server side method. Please see the code: .aspx:

function KeyCheck()
{
   var KeyID = event.keyCode;
   if(KeyID==46)
   {            
       PageMethods.Delete_files(CurrentObj.id);  
}

Now when I try to call this same method through edit, its generating following error :

Microsoft JScript runtime error: Sys.Net.WebServiceFailedException: The server method 'Delete_files' failed with the following error:

Upvotes: 1

Views: 2178

Answers (1)

Dave L
Dave L

Reputation: 1634

If you look here they discuss a similar problem. Although the last answer wasn't selected I would still recommend doing what he says. After your first parameter you can pass two function callbacks; one for a successful Ajax call and one for a failure.

Your function should look more like this:

var onDeleteSuccess = function(result) {
    //Successfully deleted files, maybe display confirmation to user.
};
var OnDeleteError = function(result) {
    //Deleting files unsuccessful, display error to user.
};
PageMethods.Delete_files(CurrentObj.id, onDeleteSuccess, OnDeleteError);

Try adding the "missing" (although they should be optional) parameters to your PageMethod call and see if that solves it.

Edit:

I found a closed bug at connect.microsoft.com about this problem. Have you tried using the page only in IE7? If so, test it in other browsers and see if it works. If it does your only option may be to upgrade IE7 to a newer version or re-open the issue.

Edit after comments:

Try placing this code before your PageMethods.Delete_files function call:

PageMethods.set_path("PageYouAreTransferringto.aspx");

I think the handler you're calling is confused about which server-side page method to call since it appears (to the browser and JavaScript) that you're on a different page.

Upvotes: 2

Related Questions