This is a migrated thread and some comments may be shown as answers.

why need Static web method in Autocomplete box using web service

1 Answer 134 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Heera
Top achievements
Rank 1
Heera asked on 17 Jan 2013, 07:55 AM
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.

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 20 Jan 2013, 08:12 AM
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
Tags
General Discussions
Asked by
Heera
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or