This is a migrated thread and some comments may be shown as answers.

Radspell: referencing textboxes in formview

8 Answers 203 Views
Spell
This is a migrated thread and some comments may be shown as answers.
fatma
Top achievements
Rank 1
fatma asked on 06 Jan 2009, 10:53 PM
Hi,

I have three formviews with multiple textboxes in a page. I am having problem referencing the textboxes in these formviews for spell check.

I am using your sample java code below, and the spell check  doesn't work.

 

function MultipleTextSource(sources)

 

{

 

this.sources = sources;

 

 

 

this.getText = function()

 

{

 

var texts = [];

 

 

for (var i = 0; i < this.sources.length; i++)

 

{

texts[texts.length] =

this.sources[i].getText();

 

}

 

return texts.join("<controlSeparator><br/></controlSeparator>");

 

}

 

 

this.setText = function(text)

 

{

 

var texts = text.split("<controlSeparator><br/></controlSeparator>");

 

 

for (var i = 0; i < this.sources.length; i++)

 

{

 

this.sources[i].setText(texts[i]);

 

}

}

}

 

function startSpell()

 

{

 

var sources =

 

[

 

new HtmlElementTextSource(document.getElementById('<%=FormView2.FindControl("TextBox4").ClientID %>')),

 

 

new HtmlElementTextSource(document.getElementById('<%=FormView3.FindControl("TextBox5").ClientID %>')),

 

 

new HtmlElementTextSource(document.getElementById('<%=FormView3.FindControl("TextBox6").ClientID %>'))

 

];

 

 

var spell = $find("RadSpell1");

 

spell.setTextSource(

new MultipleTextSource(sources));

 

spell.startSpellCheck();

}

 


<
telerik:RadSpell ID="RadSpell1" runat="server" SupportedLanguages="en-US,English" ControlsToCheck="TextBox4" IsClientID="true" ButtonType="None"/>

 

 

<input type="button" onclick="startSpell();" value="Check all" class="button"/>

 




Thanks!

8 Answers, 1 is accepted

Sort by
0
Lini
Telerik team
answered on 09 Jan 2009, 05:04 PM
Hi,

The code you have seems to be for the old RadSpell control for ASP.NET. If you are using the ASP.NET AJAX version, the code should look like this:

    <script type="text/javascript"
        function startSpell() { 
            var sources = [ 
            new Telerik.Web.UI.Spell.HtmlElementTextSource($get('<%=TextBox4.ClientID %>')), 
            new Telerik.Web.UI.Spell.HtmlElementTextSource($get('<%=TextBox5.ClientID %>')), 
            new Telerik.Web.UI.Spell.HtmlElementTextSource($get('<%=TextBox6.ClientID %>')) 
            ]; 
            var spell = $find("RadSpell1"); 
            spell.set_textSource(new Telerik.Web.UI.Spell.MultipleHtmlElementsSource(sources)); 
            spell.startSpellCheck(); 
        } 
    </script> 
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox> 
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox> 
<asp:TextBox ID="TextBox6" runat="server"></asp:TextBox> 
    <telerik:RadSpell ID="RadSpell1" runat="server" SupportedLanguages="en-US,English" 
        ControlsToCheck="TextBox4" IsClientID="true" ButtonType="None" /> 
    <input type="button" onclick="startSpell();" value="Check all" class="button" /> 

Simply replace the example textboxes in the above code with the ones in your FormView controls and you are done.

Best wishes,
Lini
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
fatma
Top achievements
Rank 1
answered on 09 Jan 2009, 08:38 PM
Hi Lini,

I am using ASP.NET AJAX version Q3 2008.
when I click the "check all" button, spell check doesn't work, and I got java script error on the page.

 

function startSpell() {

 

 

 

var sources = [

 

 

 

new Telerik.Web.UI.Spell.HtmlElementTextSource($get('<%=FormView2.FindControl("TextBox4").ClientID %>')),

 

 

 

new Telerik.Web.UI.Spell.HtmlElementTextSource($get('<%=FormView3.FindControl("TextBox5").ClientID %>')),

 

 

 

new Telerik.Web.UI.Spell.HtmlElementTextSource($get('<%=FormView3.FindControl("TextBox6").ClientID %>'))

 

];

 

 

var spell = $find("RadSpell1");

 

spell.set_textSource(

 

new Telerik.Web.UI.Spell.MultipleHtmlElementsSource(sources));

 

spell.startSpellCheck();

}

 

 

<td style="width: 26px">

 

 

 

<telerik:RadSpell ID="RadSpell1" runat="server" ControlsToCheck="TextBox4" IsClientID="true" ButtonType="None"/>

 

 

 

</td>

 

 

 

<td style="width: 26px">

 

 

 

<input type="button" onclick="startSpell();" value="Check all" class="button" />

 

 

 

<asp:Button ID="Button1" runat="server" Text="Save" OnClick="Btn_Save_Click" OnPreRender="Button1_PreRender" /></td>

 

 

 

<td style="width: 38px">

 

 

 

<asp:Button ID="Button2" runat="server" OnClick="Btn_Cancel_Click" Text="Cancel" OnPreRender="Button2_PreRender" /></td>

 

 

 


Thanks,
0
Lini
Telerik team
answered on 13 Jan 2009, 01:55 PM
Hi,

Did the code I sent you work (using the three sample textboxes instead of the formview's textboxes)? What is the JavaScript error you are getting? My guess is that the $get('<%=FormView2.FindControl("TextBox...").ClientID %>')statement is returning null for one or more of the textboxes. View the source of the page to see the rendered output and make sure that the inputs exist there as well.

Kind regards,
Lini
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
fatma
Top achievements
Rank 1
answered on 13 Jan 2009, 02:05 PM
Hi,

When I have multiple textboxes in the formview edit template with a radspell, I don't need to even use any java script it works. In this case I have to have two formviews in a page.
the sample code didn't work when I applied it with the formview. I didn't know how to assign anything to ControlsToCheck property. Since I have 2 formview with multiple textboxes.
telerik:RadSpell ID="RadSpell1" runat="server" ControlsToCheck="TextBox4" IsClientID="true" ButtonType="None"/>
when I tried to above with formview, I got the following error
Compiler Error Message: CS0030: Cannot convert type 'string' to 'string[]'

Source Error:

Line 850:    <br />
Line 851:    <br />
Line 852: <telerik:RadSpell ID="RadSpell1" ControlsToCheck='<%#FormView2.FindControl("TextBox4").ClientID %>' ButtonType="None" runat="server" />Line 853:    <br />
Line 854:    <br />


Is there any way I can have a radspell and textboxes in a formview edit template, and it works on a button click. How you can reference textboxes and the radspell in the formview? how you can reference a radspell in a formview, and run on a button click.

I tried following function on a button click, radspell even didn't display.

 

function startSpell1() {

 

 

 

var spell = document.getElementById('<%=FormView2.FindControl("RadSpell2").ClientID %>');

 

 

spell.startSpellCheck();

 


Thanks,

Thanks,

0
Lini
Telerik team
answered on 16 Jan 2009, 08:03 AM
Hi,

I notice that you are using the ControlsToCheck property of the spell checker, but with only one control. This property should be set to a list of controls - otherwise you should use the ControlToCheck.

If you want to databind more than one control in the ControlsToCheck property, you should use a string array:

<telerik:RadSpell ID="RadSpell1" ControlsToCheck='<%# new string[3] {control1.ClientID,control2.ClientID,control3.ClientID} %>' IsClientID="true" ...

also, do not forget to set IsClientID="true" if you are using the ClientID properties of the controls.

All the best,
Lini
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
michelle
Top achievements
Rank 1
answered on 11 May 2009, 11:06 PM
I am trying to spell check multiple asp:textboxes with a single button click.  I've attempted to use the code posted in this thread:
 <script type="text/javascript"
        function startSpell() { 
            var sources = [ 
            new Telerik.Web.UI.Spell.HtmlElementTextSource($get('<%=TextBox4.ClientID %>')), 
            new Telerik.Web.UI.Spell.HtmlElementTextSource($get('<%=TextBox5.ClientID %>')), 
            new Telerik.Web.UI.Spell.HtmlElementTextSource($get('<%=TextBox6.ClientID %>')) 
            ]; 
            var spell = $find("RadSpell1"); 
            spell.set_textSource(new Telerik.Web.UI.Spell.MultipleHtmlElementsSource(sources)); 
            spell.startSpellCheck(); 
        } 
    </script> 
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox> 
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox> 
<asp:TextBox ID="TextBox6" runat="server"></asp:TextBox> 
    <telerik:RadSpell ID="RadSpell1" runat="server" SupportedLanguages="en-US,English" 
        ControlsToCheck="TextBox4" IsClientID="true" ButtonType="None" /> 
    <input type="button" onclick="startSpell();" value="Check all" class="button" /> 


An exception occurs on spell.set_textSource()...object doesn't support this property or method.
I've also tried to set the ControlsToCheck property of the RadSpell check on the server side, and am unable to get the spell checker to actually check the fields identified. 

Please provide a working example of how to use the Ajax Rad Spell Check with multiple asp:textboxes.  (Version 2009 Q1).

Thanks!
Michelle Brown
0
Tervel
Telerik team
answered on 12 May 2009, 08:16 AM
Hi michelle,

Your code is probably not in an ASPX page but in a user control or page inheriting from a Master Page - hence using $find("RadSpell1");  probably returns null.

Before we examine the code further, my suggestion is to use a simple alert to make sure $find returns an object, e.g.

var spell = $find("RadSpell1");
alert(spell);


In case the alert shows null, please modify the $find line like this:
var spell = $find("<%=RadSpell1.ClientID%>");


Greetings,
Tervel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
michelle
Top achievements
Rank 1
answered on 12 May 2009, 04:58 PM
Hi Tervel,

Thank you.  This did the trick.

Michelle
Tags
Spell
Asked by
fatma
Top achievements
Rank 1
Answers by
Lini
Telerik team
fatma
Top achievements
Rank 1
michelle
Top achievements
Rank 1
Tervel
Telerik team
Share this question
or