Getting Error: 500 error when using AJAX POST to C# Webmethod

43 views Asked by At

I created a webmethod that returns an HTML string that is attached to a div at the end of a drop operation.

The first iteration of the WebMethod was named TestMethod, which worked great. When I literally changed the name of the method, the server returned a 500 error.

On the Dash1.aspx.cs page:

        [WebMethod]
        public static string GetPanelHTML(string id)
        {
            DataAccess da = new DataAccess();
            string strHTML = da.CreateVPPanel(id);

            return strHTML;
        }

        [WebMethod]
        public static string TestMethod(string id)
        {
            DataAccess da = new DataAccess();
            string strHTML = da.CreateVPPanel(id);

            return strHTML;
        }

On the client page:

    const dropzoneid = e.target.id;
    var idparm = '{ id: ' + panelID + ' }';
    
    $.ajax({
        type: "POST",
        url: '/Dash1.aspx/GetPanelHTML',
        data: idparm,
        contentType: "application/json; charset=utf-8",
        success: function (data) {
            console.log(data.d);
            $('#' + dropzoneid).html(data.d);
        },
        failure: function (response) {
            alert('failure ' + response.d);
        }
    });

If I change the url to /Dash1.aspx/TestMethod, it works. Both methods are exactly the same.

I published the project and decompiled the page dll and both methods exist.

0

There are 0 answers