Thursday, April 30, 2009

ASP.NET DIY Intellesence

As a time killer I decided to figure out a way to incorporate intellesence into an ASP.NET application.  Note this is something I worked on for a few hours without time to refactor; there could also be better ways to accomplish this.  I used jQuery to handle all my javascript needs and just your basic .NET standard TextBox and ListBox.

What exactly does this do?

Well first of all I must instill again that this is basic; you can take this code and modify it to fit your needs.  This simply renders your basic intellesence from a populated listbox.  Being that it is not complete, if someone would like to take the reigns and send me the code changes to re-publish that would be great too.  My email is gary.l.coxjr at gmail dot com.

Current Known Problems:

  • Intellesence is not showing below the text
  • Intellesence only displays when the OemPeriod is pressed ‘.’ (would be nice to be able to press “Ctrl”+”Shift”+”Space”)
  • Select from list as you type is not perfect (Doesn’t always find the right item)
  • Double-Click on listbox does not post to textbox

Please keep in mind this is NOT production code and shall not be used as such.  You may use this at your own risk.

What can be done to make this more useful?

Since the intellesence works off the listbox, any ListItems you load in there will be displayed when a period is pressed.  Whatever is selected in the listbox when you hit “Space” or “Enter” is what will be entered after the period in the textbox.  If you populate it with a list of object properties, like in my example of class Person, when a user types Person and then hits the period they will be presented with the pre-populated properties that can be selected.

The Javascript can be found in AspxIntellesence.js file located in ~/JS directory.

Here is what we see:

Intellesence

Notice I started to type “S” and the intellesence moved to StreetAddress.  If I had pressed the space bar then you would get Person.StreetAddress as the javascript would handle this.

What is this useful for anyway?

Well I think it could be very useful if your designing a template builder that allows your users to design custom email messages, or campaigns.  This type of tool would allow your customer to build the template and from your backend code process it from a given business object.  Take my example, assume I had a class named Person and the above template was processed.  I could send personalized emails to a select group that may look like:

Welcome Gary Cox,
    We have your current street listed as 123 Some Street.

Simply by parsing out the [object property] and replacing with its value of the current instance.

As always, I hope this helps someone.  Happy Coding!!!

 

Download Source Code

No comments:

 
Creative Commons License
Blogged Information and Code is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.