[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Webmethod error with Jquery Ajax post function

Posted on 2014-04-14
6
Medium Priority
?
1,138 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
Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

 

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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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.

649 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