Click here to Skip to main content
15,891,597 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Assalam-o-Alaikum,

I want to make textbox(searchbox) like facebook i.e when I am typing it is showing and changing result frequently depending upon text being written. Is it possible in asp.net c#?
Posted

1 solution

jQuery UI Autocomplete
This is called an auto-complete textbox. There is a jQuery UI widget available for this: http://jqueryui.com/autocomplete/.

In particular, click the "Remote with cache" example (from the examples list on the right of the above page) to see how to use a callback. You can click "view source" to see how they created their example. Note that you don't have to do the caching.

That callback will call a C# web service that you build. To call a web service from JavasScript, see this: http://msdn.microsoft.com/en-us/library/bb398998(v=vs.90).aspx.

You can start by creating a simple web service that just returns a list of strings (say, your 3 favorite animals, or whatever you want). Then, once you have that working, you can modify your web service to look at the term being searched for, then perform some query (e.g., against a database) to return valid results.

Pure ASP.NET Alternative
If you don't want to use jQuery, you can use this: http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/AutoComplete/AutoComplete.aspx.
 
Share this answer
 
v3
Comments
saad_lah 19-Jul-13 12:15pm    
Thank You very much! :)
saad_lah 19-Jul-13 12:31pm    
Can I use this .autocomplete function from C#?
AspDotNetDev 19-Jul-13 12:38pm    
Yes, I was able to do that a while back. The autocomplete widget has a JavaScript callback, which you can use to make an AJAX call (say, to a page method or web service written in C#) to get the values to populate the drop down.
saad_lah 19-Jul-13 13:21pm    
Yes, I want to populate data and use function through C#(because I know C# alot, but a complete noob with jquerry and javascript), So, How can I call the autocomplete function from C# code?

P.S: I have recently started web Programming in my Database course!
AspDotNetDev 19-Jul-13 13:44pm    
I updated my answer. Also, you wouldn't "call the autocomplete function from C# code". The autocomplete widget would call your callback function each time the user types into the textbox, then you'd make your callback call your C# web service, which would return the auto-complete results that get displayed in a list under the textbox.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900