Create an autocomplete textbox search in a sharepoint project using 2010


  • Hi,

    I've made an empty SharePoint project using 2010. In my project I have a user-control which include a textbox for AutoComplete search. I did Autocomplete search before in a website application using ashx handler but I don't know how can I make it in SharePoint application. (as long as I know we don't have ashx handler in sharepoint).

    I would appreciate any idea, suggestion, link or sample code .

    Thanks in advance,


    Wednesday, August 17, 2011 1:50 PM


All replies

  • Under Sharepoint you'd do it in exactly the same way. (you can use custom service applications but in my opinion thats a crazy amount of overhead)

    Chris O'Brien has a series of articles that cover the techniques that you'll need:

    Also, depending on what your autocomplete needs to do, there is one already available at icrosoft.Office.Search.WebControls.AutoCompleteExtender in the Microsoft.Office.Server.Search.dll library. It's pretty configurable and can may be be used to suit your purpose.




    Ch. - My Blog | SharePoint 2010 Application Development - My Book
    • Marked as answer by Shimin Huang Friday, August 26, 2011 7:01 AM
    Wednesday, August 17, 2011 2:42 PM
  • Thanks For reply.

    I am newbie in SharePoint programming and unfortunately I didn't get your point. This is what I want to do :

    1) Make a usercontrol in Sharepoint with following code:

    <script src="/Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="/Scripts/jquery.autocomplete.js" type="text/javascript"></script>
    <script type="text/javascript">
      $(document).ready(function () {
        $("#<%=txtSearch.ClientID%>").autocomplete('x.ashx', { delay: 0 });
      Enter Your Device Name:<br />
      <asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>

    2) I need to make an ashx handler or a webservice or anything else which I can use to load data from database and bind it to my textbox

    in application I made the following .ashx handler:

        public void ProcessRequest(HttpContext context)
          string prefixText = context.Request.QueryString["q"];
          using (SqlConnection conn = new SqlConnection())
            conn.ConnectionString = ConfigurationManager
            using (SqlCommand cmd = new SqlCommand())
              cmd.CommandText = "select assetname from asset where " +
              "assetname like @SearchText + '%'";
              cmd.Parameters.AddWithValue("@SearchText", prefixText);
              cmd.Connection = conn;
              StringBuilder sb = new StringBuilder();
              using (SqlDataReader sdr = cmd.ExecuteReader())
                while (sdr.Read())

    but now I don't know how to implement something like this in SharePoint Application. I also want to make AutoComplete as a web part and then deploy it to my SharePoint Site.

    I would really appreciate it if you can provide me step by step instruction.



    Wednesday, August 17, 2011 3:45 PM
  • Hi maryam,

    Have you got the answer of your question ? Have u implemented autosuggest in search , that pull data from database in sharepoint?

    I am looking for the solution of the above problem , where I am using sharepoint 2007.



    Monday, June 18, 2012 12:57 PM