Solved

Webmethod error with Jquery Ajax post function

Posted on 2014-04-14
6
856 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

DevOps Toolchain Recommendations

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

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Edit a page at wix.com 8 51
asp day pilot 3 21
JQuery JavaScripot loop though RadioButtonList 4 26
Javascript/JQuery - HtmlEncode (?) Ajax Result 1 40
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

803 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