Auto Complete Textbox asp.net

Auto Complete Textbox asp.net
Autocomplete, when added to an input field, enables users to quickly find and select from a pre-populated list of values as they type, leveraging searching and filtering.

How do you implement it into your own textbox?
<link href="AutoCompleteJS/jquery-ui.css" rel="stylesheet" type="text/css"></link>
<script src="AutoCompleteJS/jquery.min.js" type="text/javascript">
</script>
<script src="AutoCompleteJS/jquery-ui.min.js" type="text/javascript">
</script>
<asp:textbox id="TextBox1" runat="server" width="251px"></asp:textbox>
Add New Item Auto_Complete_Post.ashx
public void ProcessRequest(HttpContext context)
        {
            String _searchText = context.Request.QueryString["term"];

            PostClass pc = new PostClass();
            List<String> abc = pc.GetPostName();

            Collection<Auto_PostDTO> collection = new Collection<Auto_PostDTO>();
            Auto_PostDTO _IdValue;
            foreach (String str in abc)
            {
                if (str.Contains(_searchText)) // Will match once
                {
                    _IdValue = new Auto_PostDTO();
                    _IdValue.value = _IdValue.label = str;
                    _IdValue.id = str;
                    collection.Add(_IdValue);
                }
            }
           
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            string jsonString = serializer.Serialize(collection);
            context.Response.Write(jsonString);
        }
    class Auto_PostDTO
    {
        public string id { get; set; }
        public string label { get; set; }
        public string value { get; set; }
    }

Add texbox onfocus event coding
protected void Page_Load(object sender, EventArgs e)
        {
            String _scriptAuthor1 = "javascript:$(function () { " +
                                   " $(" + TextBox1.ClientID + ").autocomplete({ " +
                                   " source: 'Auto_Complete_Post.ashx' " +
                                   " }); " +
                                   " });";
            TextBox1.Attributes.Add("onfocus", _scriptAuthor1);
        }
Download Code Here
Auto Complete Textbox asp.net Auto Complete Textbox asp.net Reviewed by Bhaumik Patel on 7:11 AM Rating: 5