Daily using/supporting

Get Firefox browser!
Get Thunderbird!
Get Opera browser!
Get The Gimp!
Get Inkscape!
Get LibreOffice!
Get Videolan!
Get Linux!
Get Mandriva!
Get Joomla!
Hacker Emblem

Archives

Which topics would you like us to cover more?

Latest comments

Latest tweets

about 1 day ago Using REDIPS.drag to add drag and drop to your .Net webapplication #li #dib0 http://t.co/n8zY3s7d
about 7 days ago http://t.co/cknQcDbo #Kindle
about 15 days ago Freedom isn't the ability to choose what to do or say, but the ability to choose what not to do or say #freedom
about 29 days ago http://t.co/61KTQknI #Kindle
12 Apr 2012 Force the use of a networking adapter using C# #li #dib0 http://t.co/ZTJOPzOz
9 Apr 2012 Mandriva 2010.2 and USB devices in Virtualbox http://t.co/fwq9gbHB
9 Apr 2012 Execute a http request to you own site with PHP http://t.co/DIvWPrpd
Home Architecture, security and coding How to show possibilities in AutoCompleteExtender without user input
How to show possibilities in AutoCompleteExtender without user input
Written by Division by Zero   
Friday, 20 August 2010 11:17

The AjaxControlToolkit AutoCompleteExtender uses user input to show suggestions. Sometimes this is nog enough. It's not quite user friendly if an user doesn't know what to enter and has to guess something. As an alternative you can use a button to show some suggestions. Here's how to dot that.

You have an input field with an AutoCompleteExtender and add an button.

<asp:TextBox ID="tbSelectUser" CssClass="Textbox" runat="server" Width="146px" />
 <acc:AutoCompleteExtender ID="aceSelectUser" runat="server" TargetControlID="tbSelectUser" MinimumPrefixLength="1"
 ServicePath="~/Service/Users.asmx" ServiceMethod="GetUserNameSuggestions" EnableCaching="true" CompletionInterval="5"  />
 <input id="btnShowUsernames" type="button" class="Button" runat="server" />

With the following Javascript you are able to show suggestions without entering some text.

function showAutoComplete(elemName)
{
 showAutoComplete(elemName, false);
}

function showAutoComplete(elemName, enableContext)
{
 var autoComplete = $find(elemName);
 autoComplete.get_element().focus();
 autoComplete._textBoxHasFocus = true;
 autoComplete.get_element().value = '';

 if (enableContext)
 {
 Sys.Net.WebServiceProxy.invoke(autoComplete.get_servicePath(), autoComplete.get_serviceMethod(), false,
 { prefixText: '', count: autoComplete._completionSetCount, contextKey: autoComplete._contextKey },
 Function.createDelegate(autoComplete, autoComplete._onMethodComplete),
 Function.createDelegate(autoComplete, autoComplete._onMethodFailed),
 '',
 5000);
 }
 else
 {
 Sys.Net.WebServiceProxy.invoke(autoComplete.get_servicePath(), autoComplete.get_serviceMethod(), false,
 { prefixText: '', count: autoComplete._completionSetCount },
 Function.createDelegate(autoComplete, autoComplete._onMethodComplete),
 Function.createDelegate(autoComplete, autoComplete._onMethodFailed),
 '',
 5000);
 }

 $common.updateFormToRefreshATDeviceBuffer();
}

Now you just have to add the javascript to the button and you're ready to rock.

btnShowUsernames.Attributes["onclick"] = string.Format("showAutoComplete('{0}');", aceAcceptUser.ClientID);
 

Add comment


Security code
Refresh

Its name is Public Opinion. It is held in reverence. It settles everything. Some think it is the voice of God. - Mark Twain


© 2009 - 2012, Division by Zero

Template based on the empire template by joomlashack 

Valid XHTML 1.0 Strict  Valid CSS!  Creative Commons License
This work by Division by Zero is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Netherlands License.