It seems like you are aiming for a server-side approach to implement an autocomplete feature. In ASP.NET web app,
Page_Load
event isn't the place to implement that. You would typically use the
TextChanged
event of the
TextBox
. But you should be careful when taking to this route as
TextChange
event causes the server to fire and trigger a
postback
and hits your database each time you change/type something in the
TextBox
. You could surely cache the data at once to reduce database calls but still you need to rebind your data control with the search results - which is kinda expensive.
Your closest option if you want to avoid doing some client-side scripting is using :
AutoComplete Sample[
^]
Here's an article that shows how to use it:
AutoCompleteExtender in ASP.Net
[
^]
The ideal way to implement an autocomplete feature is using a client-side approach with
AJAX
. You could use
jQuery
as already suggested by others and couple that with AJAX to communicate with your data from your database. Here's a great writeup about:
Many ways to communicate with your database using jQuery AJAX and ASP.NET[
^]
Once you get a good grasp on how the web works regarding communicating your data from the server to the client, then you can start working on your autocomplete feature. There are tons of examples in the net that are available. Here are a few of them:
TextBox AutoComplete with ASP.NET and jQuery UI | DotNetCurry[
^]
Populate jQuery AutoComplete TextBox from Database using Web Service in ASP.Net
JQuery - Auto Complete Text Box In ASP.Net