why need Static web method in Autocomplete box using web service

2 posts, 0 answers
  1. Heera
    Heera avatar
    11 posts
    Member since:
    Dec 2011

    Posted 17 Jan 2013 Link to this post

    Aspx page(Test.aspx)


     <telerik:RadScriptManager ID="RadScriptManager1" runat="server" EnablePageMethods="true">
        </telerik:RadScriptManager>

    <telerik:RadAutoCompleteBox ID="RadAutoCompleteBox1" runat="server" Width="250" DropDownHeight="150"
            DropDownWidth="250">
                    <WebServiceSettings Method="GetCompanyNames" Path="Test.aspx" />
        </telerik:RadAutoCompleteBox>



    Test.cs

     [System.Web.Services.WebMethod()]
            [System.Web.Script.Services.ScriptMethod()]
            public static AutoCompleteBoxData GetCompanyNames(object context)
            {


     string searchString = ((Dictionary<string, object>)context)["Text"].ToString();
                //DataTable data = GetChildNodes(searchString);
                DataTable data = new DataTable();

    SqlConnection conn = new SqlConnection(connectionstring);
                string sql = "SELECT ID,NAME  FROM T_Patient WHERE NAME LIKE '" + searchString + "%'";
                SqlDataAdapter da = new SqlDataAdapter(sql, conn);
                da.Fill(data);

                List<AutoCompleteBoxItemData> result = new List<AutoCompleteBoxItemData>();

                foreach (DataRow row in data.Rows)
                {
                    AutoCompleteBoxItemData childNode = new AutoCompleteBoxItemData();
                    childNode.Text = row["NAME"].ToString();
                    childNode.Value = row["ID"].ToString();
                    result.Add(childNode);
                }

                AutoCompleteBoxData res = new AutoCompleteBoxData();
                res.Items = result.ToArray();

                return res;
    }


    Some Error is occured when public static AutoCompleteBoxData GetCompanyNames(object context) replace to public AutoCompleteBoxData GetCompanyNames(object context) [remove static keywords]

    i am not use public web method or any other idea use only public method /public static method.

    THE SERVER METHOD  'GetCompanyNames
    '  FAILED.

    please give me solution.

    thank you.

  2. Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 20 Jan 2013 Link to this post

    Hello,

    We have to use Static web method. Because this is the functionality from the .net.

    http://encosia.com/why-do-aspnet-ajax-page-methods-have-to-be-static/

    Thanks,
    Jayesh Goyani
Back to Top