Solved

Webmethod error with Jquery Ajax post function

Posted on 2014-04-14
6
757 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
creating a flowchart from an algorithm 5 22
CSS Divs in Safari 3 19
AWS CLI issues with Tags 3 30
Different Delete Messages 7 19
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…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
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)

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now