views:

165

answers:

1

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:

+1  A: 

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.

Dave L
Thanks for your reply.I tried the other function command with 3 arguments. But unfortunately, the error message is same. I have also seen the given microsoft link, and even they have not answered the question. They have closed the request just by saying they are not able to reproduce the problem OR it is a browser related issue.Please let me know if you have any other clue.Thanks in advance.
OK I found something.If I navigate from last page to my current page using Response.Redirect() then things works nicely. But if I use Server.transfer() then the AJAX gives the above error.I have no clue why it is behaving like this... Unfortunately I cannot go back and change the server.transfer to response.redirect.. becoz lot of coding is already done on that basis... So here I am still looking for a work around for teh same error.Please.. suggest some approach.Thanks.