Friday, March 5, 2010

c#: Spell checker control using jQuery

Recently I needed to add spell checking functionality to a web page. I wanted to exclude a list of strings from spell checking (like first and last names) and this list of exclusions should be customizable easily. I couldn't find any controls that fits into this need in the aspnet world.
I found this article that uses php and google's spell checking api with jQuery. I thought of porting this as an aspnet control so that I can use it without adding too much scripts on any aspnet pages.


Most of the heavy work is already done by the original author, so all I need to do was call google's api, parse the result and return the result as a JSON object to jQuery. Once the JSON is received, we build a div element with the bad spelled words with a click handler to get the suggestions. When building the div element, use the parent element's width and some images to show the progress or no bad words indicator. Wrap all these scripts and images in a server side control, so to use the spell checker, add the control to the web page and set the TargetControlID to the textbox's ID.




download code

-paul