khaleel shaik

khaleel shaik

  • NA
  • 41
  • 70.9k

AutoCompleteExtender control in user Control

Mar 29 2013 8:34 AM
I have removed the .asmx file and now try to run the Webmethod directly in the .ascx instead.

It works in a ASP.net WebApplication Webform(.Aspx Web Form)

[System.Web.Services.WebMethod]
        public static string[] GetNames(string prefixText, int count)
        {
            List<String> hits = new List<String>();
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = "Data Source=(local);Initial Catalog=umbracodb;Integrated Security=True";
            conn.Open();
            SqlCommand cmd = conn.CreateCommand();
            cmd.Parameters.Add("@Input", SqlDbType.VarChar, 50);
            cmd.Parameters["@Input"].Value = "%" + prefixText + "%";
            cmd.CommandText = "SELECT [Name] FROM [Product] WHERE [Name] like @Input";
            cmd.ExecuteNonQuery();
            SqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                hits.Add(reader["Name"].ToString());
            }
            conn.Close();
            conn.Dispose();
            return hits.ToArray();
        }