Spell Check Web Service in Share Point - Excluding SharePoint Controls
Todays task seemed simple enough, get the spell check web service running on a custom control embedded in a share point page. Where to start? Looking for documentation on the web I could not find anything remotely helpful until I stumbled upon a blog by Hoo Kai Sheng. This helped get the ball rolling. It out lines the easiest way to get the spell checker working, that is using the SpellCheckEntirePage javascript function.
As the name suggests this spell checks all the text fields on page. It skips drop down lists and multiple select boxes but any other form control with a text input seems fair game. This means Share Point controls such as the people picker (SharePoint:PeopleEditor) will get checked as well. This is not very user friendly as we do not want the checker asking people to fix their domain names and user names.
The trick to exclude SP controls is to search the page the SP is on and find the text input box that resides within it. In this case the SharePoint:PeopleEditor contains several hidden fields, we don't need to worry about these, and also an input field which is called "downlevelTextBox". This is the one we want to exclude. Because we are using custom ascx controls, in the code behind, we can use the FindControl method on our SharePoint:PeopleEditor. In the example below textboxEscalationManager is the people picker ID.
TextBox textboxEscalationManager = (TextBox)PeopleEditorEscalationManager.FindControl("downlevelTextBox");
textboxEscalationManager.Attributes.Add("excludeFromSpellCheck", "true");
When the page renders the control it now has the attribute - excludeFromSpellCheck and will not be checked by the Spell Checker.