I have multiple textboxes that need spelled checked, I placed a WebSpellChecker control on the page for each text box, but when I click the button the dialog flashes a few times, and i only see the text for the last text box being checked....and it disapears....can't fix any errors.
How can I do this?
Also, is there a way to know that the spell check has been completed so that I can display a save button only after the spellcheck has been run?
HI NervousRex,
i created sample page that spell checks two webtextedit controls and enables a webimagebutton when the spell checking completes.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="Infragistics2.WebUI.WebDataInput.v7.3, Version=7.3.20073.1043, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" Namespace="Infragistics.WebUI.WebDataInput" TagPrefix="igtxt" %><%@ Register Assembly="Infragistics2.WebUI.WebSpellChecker.v7.3, Version=7.3.20073.1043, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" Namespace="Infragistics.WebUI.WebSpellChecker" TagPrefix="ig_spell" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title>
<script id="igClientScript" type="text/javascript"><!--function checkspelling(){//debugger; var spellchecker1 = ig_getWebControlById("WebSpellChecker1"); var text1 = igedit_getById("WebTextEdit1") spellchecker1.checkSpelling(text1.getText()); var spellchecker2 = ig_getWebControlById("WebSpellChecker2"); var text2 = igedit_getById("WebTextEdit2") spellchecker2.checkSpelling(text2.getText()); }
function WebSpellChecker1_SpellCheckComplete(oWebSpellChecker, oEvent, uncheckedText, checkedText){ //Add code to handle your event here. }
function Button1_onclick() {checkspelling();}
function WebSpellChecker2_SpellCheckComplete(oWebSpellChecker, oEvent, uncheckedText, checkedText){ //Add code to handle your event here.// debugger; var button = ig_getWebControlById("WebImageButton1"); button.setEnabled(true);}// --></script> </head><body> <form id="form1" runat="server"> <div> <igtxt:WebTextEdit ID="WebTextEdit1" runat="server"> </igtxt:WebTextEdit> <igtxt:WebTextEdit ID="WebTextEdit2" runat="server"> </igtxt:WebTextEdit> <ig_spell:WebSpellChecker ID="WebSpellChecker1" runat="server" StyleSetName="" StyleSetPath="" StyleSheetDirectory="" TextComponentId="WebTextEdit1"> <ClientEvents SpellCheckComplete="WebSpellChecker1_SpellCheckComplete" /> </ig_spell:WebSpellChecker> <ig_spell:WebSpellChecker ID="WebSpellChecker2" runat="server" StyleSetName="" StyleSetPath="" StyleSheetDirectory="" TextComponentId="WebTextEdit2"> <ClientEvents SpellCheckComplete="WebSpellChecker2_SpellCheckComplete" /> </ig_spell:WebSpellChecker> </div> <input id="Button1" type="button" value="button" onclick="return Button1_onclick()" /> <igtxt:WebImageButton ID="WebImageButton1" runat="server" OnClick="WebImageButton1_Click"> </igtxt:WebImageButton> </form></body></html>
The problem with this approach - if you correct a spelling in one control and then select "Change all" or ignore misspeling and then select "Ignore all" - this will work within current control only. If the same misspeling happens in the next control - user will get prompted again. Is there any way to remember what corrections were made from control to control in case of "...All" was clicked so user won't get prompted again?
So, how about this approach:
1. when you click your "Check Spelling" button, collect the content of the various textboxes, etc into an xml string that looks like this:
<ControlsToCheck>
<IDofControl1>contents of textbox 1</IDofControl1>
<IDofControl2>contents of textbox 1</IDofControl2>
...
</ControlsToCheck>
2. In your WebSpellChecker, set AllowXML to true. Then, using the spellchecker object:
oWebSpellChecker.checkSpelling(xml string from above)
3. In the completion callback, crack the xml using Microsoft.XMLDOM ActiveXObject (see also http://msdn2.microsoft.com/en-us/library/aa468547.aspx), loadXML method.
4. Go through the name/value pairs, and for each one, get the control (i.e., textbox) whose ID is the "name", and set its text to the "value" (i.e., the corrected text).
This allows you to
1. check multiple controls with just one invocation of the spell check dialog
2. only create one annoying flash if the text was spelled correctly in the first place, instead of one for every control
3. hit "ignore all" and have it really ignore all, instead of having to do this once per control.
It's a little tricky, but works pretty well.
-Scott
Hi All,
I have a question regarding this:
I'm using the method described to spell check multiple fields. I have a "checkspelling()" method in Javascript which is called when the user clicks the spell checker button. This method loads my form data in to XML:
storeXML += "<Field index=\"" + i.toString() + "\">";storeXML += xmlEscape(form_textboxes[i].value);storeXML += " </Field>"; I use a function called "xmlEscape" to encode illegal character such as "<" or "&". This is working well and the data appears correctly in the spell checker dialog. When the spell check is complete I am handling the "SpellCheckComplete" event with another method. The problem I have is that the data that is coming back from the spell checker dialog has not been escaped and the method is failing: WebSpellChecker_SpellCheckComplete(oWebSpellChecker, oEvent, uncheckedText, checkedText) { WebSpellChecker_SpellCheckComplete(oWebSpellChecker, oEvent, uncheckedText, checkedText) { var oXml = new ActiveXObject("Microsoft.XMLDOM"); //checkedText is not escaped so this line fails oXml.loadXML(checkedText);
storeXML +=
"<Field index=\"" + i.toString() + "\">";storeXML += xmlEscape(form_textboxes[i].value);storeXML += " </Field>";
I use a function called "xmlEscape" to encode illegal character such as "<" or "&". This is working well and the data appears correctly in the spell checker dialog. When the spell check is complete I am handling the "SpellCheckComplete" event with another method.
The problem I have is that the data that is coming back from the spell checker dialog has not been escaped and the method is failing: WebSpellChecker_SpellCheckComplete(oWebSpellChecker, oEvent, uncheckedText, checkedText) { WebSpellChecker_SpellCheckComplete(oWebSpellChecker, oEvent, uncheckedText, checkedText) { var oXml = new ActiveXObject("Microsoft.XMLDOM"); //checkedText is not escaped so this line fails oXml.loadXML(checkedText);
WebSpellChecker_SpellCheckComplete(oWebSpellChecker, oEvent, uncheckedText, checkedText) {
var oXml = new ActiveXObject("Microsoft.XMLDOM");
//checkedText is not escaped so this line fails oXml.loadXML(checkedText);
So for exampe. Entering this text in a text box:
<< >>> && ""Will produce this input in checkSpelling():
<Field index='1'><< >>> && ""</Field>
But this argument is passed to SpellCheckComplete():
<Field index='1'><< >>> && ""</Field>
Which crashes the script as the xml cannot be parsed. Does anyone know of a solution?
Thanks,
P.S. apologies for the dodgy formatting of this post. I couldn't figure out how to set the fonts
Just an update:
I've tried using CDATA tags to encode the input. This works insofar that they are passed through and the XML remains valid in the SpellCheckComplete handler. The problem is that they show up in the spell checker dialog and also seem to be confusing it as sometimes it doesn't report obvious errors.
Anyone have any other ideas?
Cheers,