ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Display AutoComplete result on TextBox focus in ASP.Net<p>Hi <a class="username" rel="chetan"> chetan</a>,</p> <p>Please refer below sample.</p> <p>You need to set the <span style="text-decoration: underline;">minLength</span> property of the jQuery AutoComplete plugin to 0 which is forcing the jQuery AutoComplete plugin to perform a Search when the TextBox is focused.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;script src=&#34;http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.10.0.min.js&#34; type=&#34;text/javascript&#34;&gt;&lt;/script&gt; &lt;script src=&#34;http://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.2/jquery-ui.min.js&#34; type=&#34;text/javascript&#34;&gt;&lt;/script&gt; &lt;link href=&#34;http://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.2/themes/blitzer/jquery-ui.css&#34; rel=&#34;Stylesheet&#34; type=&#34;text/css&#34; /&gt; &lt;script type=&#34;text/javascript&#34;&gt; $(function () { $(&#34;[id*=txtSearch]&#34;).autocomplete({ source: function (request, response) { $.ajax({ url: &#39;Default.aspx/GetFruits&#39;, data: &#34;{ &#39;prefix&#39;: &#39;&#34; + request.term + &#34;&#39;}&#34;, dataType: &#34;json&#34;, type: &#34;POST&#34;, contentType: &#34;application/json; charset=utf-8&#34;, success: function (data) { if (data.d.length &gt; 0) { response($.map(data.d, function (item) { return { label: item.split(&#39;-&#39;)[0], val: item.split(&#39;-&#39;)[1] }; })) } else { response([{ label: &#39;No results found.&#39;, val: -1}]); } } }); }, select: function (e, u) { if (u.item.val == -1) { return false; } }, minLength: 0 }).focus(function () { $(this).autocomplete(&#34;search&#34;); }); }); &lt;/script&gt; &lt;div class=&#34;searcharea col-sm-12&#34;&gt; &lt;div class=&#34;col-sm-12 col-xs-12&#34;&gt; &lt;div class=&#34;input-group custom-search-input&#34; style=&#34;padding-top: 290px;&#34;&gt; &lt;input id=&#34;txtSearch&#34; runat=&#34;server&#34; type=&#34;text&#34; class=&#34;form-control&#34; placeholder=&#34;Search By Keyword&#34; /&gt; &lt;span class=&#34;input-group-btn&#34;&gt; &lt;button id=&#34;btnsearch&#34; runat=&#34;server&#34; type=&#34;submit&#34; class=&#34;btn btn-warning&#34;&gt; &lt;span class=&#34;glyphicon glyphicon-search&#34;&gt;&lt;/span&gt;SEARCH &lt;/button&gt; &lt;/span&gt; &lt;/div&gt; &lt;!-- /input-group --&gt; &lt;/div&gt; &lt;/div&gt;</pre> <p><strong>C#</strong></p> <pre class="brush: csharp">[System.Web.Services.WebMethod] public static string[] GetFruits(string prefix) { List&lt;string&gt; fruits = new List&lt;string&gt;(); fruits.Add(&#34;Mango&#34;); fruits.Add(&#34;Apple&#34;); fruits.Add(&#34;Banana&#34;); fruits.Add(&#34;Orange&#34;); fruits.Add(&#34;Pineapple&#34;); fruits.Add(&#34;Guava&#34;); fruits.Add(&#34;Grapes&#34;); fruits.Add(&#34;Papaya&#34;); return fruits.Where(f =&gt; f.ToLower().IndexOf(prefix.ToLower()) != -1).ToArray(); }</pre> <p><strong><u>VB.Net</u></strong></p> <pre class="brush: vb">&lt;System.Web.Services.WebMethod&gt; Public Shared Function GetFruits(ByVal prefix As String) As String() Dim fruits As List(Of String) = New List(Of String)() fruits.Add(&#34;Mango&#34;) fruits.Add(&#34;Apple&#34;) fruits.Add(&#34;Banana&#34;) fruits.Add(&#34;Orange&#34;) fruits.Add(&#34;Pineapple&#34;) fruits.Add(&#34;Guava&#34;) fruits.Add(&#34;Grapes&#34;) fruits.Add(&#34;Papaya&#34;) Return fruits.Where(Function(f) f.ToLower().IndexOf(prefix.ToLower()) &lt;&gt; -1).ToArray() End Function</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://i.imgur.com/ngdiw2z.gif" alt="" width="318" height="168" /></p>https://www.aspforums.net:443/Threads/162369/Display-AutoComplete-result-on-TextBox-focus-in-ASPNet/https://www.aspforums.net:443/Threads/162369/Display-AutoComplete-result-on-TextBox-focus-in-ASPNet/Mon, 16 Jul 2018 01:16:47 GMT