Solved

Webmethod error with Jquery Ajax post function

Posted on 2014-04-14
6
933 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

740 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