-1

I am using JqueryUI autocomplete widget with asp.net i create one class file that contain method that will return list of search result. and on aspx page i called all required jquery file. on Script part i write below code:

<script type="text/javascript">
    $(document).ready(function () {
        $("#txtSearch").autocomplete({
            source: function (request, response) {
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "CommonOperation.cs/GetClientName",
                    data: "{'SearchVal':'" + document.getElementById('<%=txtSearch.ClientID%>').value + "'}",
                    dataType: "json",
                    success: function (data) {
                        response(data.d);
                    },
                    error: function (result) {
                        alert("Error......");
                    }
                });
            }
        });
    });
</script>

don't know what problem is their but when i run it always goes in Error part.

3 Answers3

1

You can't put your web method in a class file, as the method itself needs to be web-accessible.

Move it to a standard ASPX page's code-behind, and use the .aspx link instead of .cs.


An alternative would simply be to use an .asmx, and attach your class to that instead. This answer provides some information on that:

You could use something like an asmx (ASP.Net web service) that exposes the webmethods. The file is basically just a markup place holder that points at a class file. Contents are just:

<%@ WebService Language="C#" CodeBehind="~/foo/MyClass.cs" Class="MyClass" %>

Then your class has to inherit from System.Web.Services.WebService and you should be good.

If you do an add file from Visual Studio and add a web service file you can get it to create all this for you.

Tyler Roper
  • 21,445
  • 6
  • 33
  • 56
0

here url should be like this-> url:"CommonOperation.aspx/GetClientName",

Hinal
  • 35
  • 7
-1

Done It Method will be static and declared as WebMethod and Call it from aspx.cs

  • Rather than posting your own answer to confirm that someone else's worked, you should just instead accept the original correct answer. – Tyler Roper Jun 09 '17 at 19:31