0

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="PWC" Namespace="PWC" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<PWC:Planning runat="server" SkinFileName="Core/Planning.ascx" ID="Planning" Secured="true"/>

     $("#dialog-form").dialog({
         autoOpen: false,
         height: 300,
         width: 350,
         modal: true,
         buttons: {
             "Create clone": function () {

                 var cloneItem = $('input[name=item]').is(":checked");                
                 var intID = $(this).data('intID');

                 var bValid = true;
                 bValid = bValid && checkSelections();

                 if (bValid) {

$.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
          });

      $(this).dialog("close");

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?

1 Answers1

0

There are two things that might be the problem. First thing is you need to some code in web.config.

<system.web>
  <httpModules>
    <add name="ScriptModule" type="System.Web.Handlers.ScriptModule,System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
  </httpModules>
</system.web>

See the reference : Call ASP.NET PageMethod/WebMethod with jQuery - returns whole page

Another thing is you need to use JSON.stringify in parameter while posting this data.

See the reference - http://www.asp.net/ajaxlibrary/jquery_webforms_retrieve_data_from_pagemethod.ashx

Community
  • 1
  • 1
Jalpesh Vadgama
  • 13,653
  • 19
  • 72
  • 94
  • Thanks for you response Jalpesh. I already have the web.config reference. However with Json.Stringify I get the error: JavaScript runtime error: Object doesn't support property or method 'stringify'. I have the following code in my Master Page: – DaveRud Apr 14 '14 at 14:36
  • I have resolved the Stringify error but I'm still getting my original error: System.ArgumentException: Unknown web method CloneItem. Parameter name: methodName Any other ideas please? – DaveRud Apr 14 '14 at 15:02
  • did you added reference to ajaxtoolkit? – Jalpesh Vadgama Apr 15 '14 at 04:53
  • Thanks Jalpesh. Yes, AjaxToolkit is fine. I have resolved the issue by moving the Webmethod to the ASPX page itself. The jquery dialog remains in the ASCX page. I'm still not sure why the Webmethod cannot be placed in the ASCX file though. – DaveRud Apr 16 '14 at 08:44