Solved

Webmethod error with Jquery Ajax post function

Posted on 2014-04-14
6
885 Views
Last Modified: 2015-07-03
In an asp.net 3.5 website, I have a jquery located in an ASPX page that should execute a function in code-behind. I have used a webmethod approach.

Here is the error:
System.ArgumentException: Unknown web method CloneItem.
Parameter name: methodName

Here is the relevant code:

ASPX page with relevant part of Jquery:

<%@ Page Language="VB" MasterPageFile="~/Pages/MasterPage.master" Title="Planning" %>
<%@ Register TagPrefix="PMW" Namespace="PMW" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<PWC:Planning runat="server" SkinFileName="Core/Planning.ascx" ID="Planning" Secured="true"/>

 $.ajax(
           {
            type: 'POST',
            url: 'Planning.aspx/CloneItem',                                  
            data: "{'intid': '" + $(this).data('intID') + "', 'item': '" + cloneItem + "'}" ,          
            dataType: 'json',
            contentType: 'application/json; charset=utf-8'
             // success: cloneOnSuccess,
            // error: cloneOnError
            });

Function in Planning.aspx vb code-behind:

Imports System.Web
Imports System.Web.Services

   <WebMethod(EnableSession:=True)> _
        Public Shared Function CloneItem(intID As String, item As Boolean) As String
           
   'execute a stored procedure here

            Return "success!"
        End Function

Master page has the following scriptmanager

      <AJAXToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server" AsyncPostBackTimeOut="600" EnablePartialRendering="true"  CombineScripts="false" ScriptMode="Release" EnablePageMethods="true" >
        </AJAXToolkit:ToolkitScriptManager>

Any idea on what I am doing wrong?
0
Comment
Question by:Al230762
  • 4
  • 2
6 Comments
 
LVL 5

Expert Comment

by:jayakrishnabh
ID: 39998539
Change the input param name in data to intID as in the webmethod.

data: "{'intID': '" + $(this).data('intID') + "', 'item': '" + cloneItem + "'}".
0
 

Author Comment

by:Al230762
ID: 39998568
Thanks jayakrishnabh. I was really hoping the solution would be something as simple as that but unfortunately the error is the same.
0
 
LVL 5

Expert Comment

by:jayakrishnabh
ID: 39998581
Try replacing input values with temp data as below
data: "{'intID': '" + 2 + "', 'item': '" + false + "'}"
If that calls the method, then $(this).data('intID') or cloneItem would be giving error
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Accepted Solution

by:
Al230762 earned 0 total points
ID: 39998586
Thanks jayakrishnabh but this is not the issue. I tried your suggestion but see the same error. Also, when I inspect with Firebug and look at the Json Post data it looks fine i.e.:

Source
{'intID': '15847', 'item': 'false'}

It seems like the Ajax Post is simply not recognising the webmethod for some reason.
0
 

Assisted Solution

by:Al230762
Al230762 earned 0 total points
ID: 40855434
Many thanks jayakrishnabh  for the suggested solutions but because we couldn't resolve the issue we have now decided to use the  AjaxToolkit:ModalPopupExtender for this purpose which works fine.
0
 

Author Closing Comment

by:Al230762
ID: 40865055
Unfortunately we could never resolve the issue and so tried a different approach with AjaxToolkit:ModalPopupExtender which has worked fine.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question