演示radSpell动态给多textbox一次性从头到尾做拼写检查
一.静态绑定
也就是在html代码中把需要拼写检查的textbox写死在js代码中
1.1建立测试页面,copy如下html代码,然后就ok了
<HTML>
<body class="BODY">
<form runat="server" id="mainForm" method="post" style="WIDTH:100%">
<table width="98%">
<tr>
<td class="text">
<b>Spellchecking three text areas with a single dialog.</b><br>
</td>
</tr>
<tr>
<td class="text">
<textarea id="textarea1" rows="6" cols="50" style="WIDTH:360px">My firzt client side TEXTAREA with some delibirate mistakees.</textarea>
<br>
</td>
</tr>
<tr>
<td class="text">
<textarea id="textarea2" rows="6" cols="50" style="WIDTH:360px">My secont client side TEXTAREA with some delibirate mistakees.</textarea>
<br>
</td>
</tr>
<tr>
<td class="text">
<textarea id="textarea3" rows="6" cols="50" style="WIDTH:360px">My thirdth client side TEXTAREA with some delibirate mistakees.</textarea>
<br>
</td>
</tr>
</table>
<input type="button" onclick="startSpell();" value="Check all" class="button">
<script type="text/javascript">
/*<![CDATA[*/
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('textarea1')),
new HtmlElementTextSource(document.getElementById('textarea2')),
new HtmlElementTextSource(document.getElementById('textarea3'))
];
//debugger;
var spell = RadSpell.getSpellChecker('<%= RadSpell1.ClientID %>');
spell.setTextSource(new MultipleTextSource(sources));
spell.startSpellCheck();
}
/*]]>*/
</script>
<radS:RadSpell id="RadSpell1" Runat="server"></radS:RadSpell>
</form>
</body>
</HTML>
二.动态绑定<body class="BODY">
<form runat="server" id="mainForm" method="post" style="WIDTH:100%">
<table width="98%">
<tr>
<td class="text">
<b>Spellchecking three text areas with a single dialog.</b><br>
</td>
</tr>
<tr>
<td class="text">
<textarea id="textarea1" rows="6" cols="50" style="WIDTH:360px">My firzt client side TEXTAREA with some delibirate mistakees.</textarea>
<br>
</td>
</tr>
<tr>
<td class="text">
<textarea id="textarea2" rows="6" cols="50" style="WIDTH:360px">My secont client side TEXTAREA with some delibirate mistakees.</textarea>
<br>
</td>
</tr>
<tr>
<td class="text">
<textarea id="textarea3" rows="6" cols="50" style="WIDTH:360px">My thirdth client side TEXTAREA with some delibirate mistakees.</textarea>
<br>
</td>
</tr>
</table>
<input type="button" onclick="startSpell();" value="Check all" class="button">
<script type="text/javascript">
/*<![CDATA[*/
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('textarea1')),
new HtmlElementTextSource(document.getElementById('textarea2')),
new HtmlElementTextSource(document.getElementById('textarea3'))
];
//debugger;
var spell = RadSpell.getSpellChecker('<%= RadSpell1.ClientID %>');
spell.setTextSource(new MultipleTextSource(sources));
spell.startSpellCheck();
}
/*]]>*/
</script>
<radS:RadSpell id="RadSpell1" Runat="server"></radS:RadSpell>
</form>
</body>
</HTML>
也就是在后台动态换取页面textbox来做拼写检查,而不用写死在js中
2.1建立测试页面,copy如下html代码
<HTML>
<HEAD>
<title>WebForm4</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<radS:RadSpell id="RadSpell1" style="Z-INDEX: 101; LEFT: 112px; POSITION: absolute; TOP: 344px"
Runat="server"></radS:RadSpell>
<table width="98%">
<tr>
<td class="text">
<b>Spellchecking three text areas with a single dialog.</b><br>
</td>
</tr>
<tr>
<td class="text">
<asp:TextBox id="TextBox1" Text="My firzt client side TEXTAREA with some delibirate mistakees."
runat="server" TextMode="MultiLine" Width="288px" Height="64px"></asp:TextBox>
<br>
</td>
</tr>
<tr>
<td class="text">
<asp:TextBox id="TextBox2" Text="My secont client side TEXTAREA with some delibirate mistakees."
runat="server" TextMode="MultiLine" Width="288px" Height="64px"></asp:TextBox>
<br>
</td>
</tr>
<tr>
<td class="text">
<asp:TextBox id="TextBox3" Text="My thirdth client side TEXTAREA with some delibirate mistakees."
runat="server" TextMode="MultiLine" Width="288px" Height="72px"></asp:TextBox>
<br>
</td>
</tr>
</table>
<input type="button" onclick="startSpell();" value="Check all" class="button">
</form>
</body>
</HTML>
2.2copy如下cs代码<HEAD>
<title>WebForm4</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<radS:RadSpell id="RadSpell1" style="Z-INDEX: 101; LEFT: 112px; POSITION: absolute; TOP: 344px"
Runat="server"></radS:RadSpell>
<table width="98%">
<tr>
<td class="text">
<b>Spellchecking three text areas with a single dialog.</b><br>
</td>
</tr>
<tr>
<td class="text">
<asp:TextBox id="TextBox1" Text="My firzt client side TEXTAREA with some delibirate mistakees."
runat="server" TextMode="MultiLine" Width="288px" Height="64px"></asp:TextBox>
<br>
</td>
</tr>
<tr>
<td class="text">
<asp:TextBox id="TextBox2" Text="My secont client side TEXTAREA with some delibirate mistakees."
runat="server" TextMode="MultiLine" Width="288px" Height="64px"></asp:TextBox>
<br>
</td>
</tr>
<tr>
<td class="text">
<asp:TextBox id="TextBox3" Text="My thirdth client side TEXTAREA with some delibirate mistakees."
runat="server" TextMode="MultiLine" Width="288px" Height="72px"></asp:TextBox>
<br>
</td>
</tr>
</table>
<input type="button" onclick="startSpell();" value="Check all" class="button">
</form>
</body>
</HTML>
public class WebForm4 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.TextBox TextBox3;
protected Telerik.WebControls.RadSpell RadSpell1;
StringBuilder second = new StringBuilder();
private void Page_Load(object sender, System.EventArgs e)
{
SecondScript(this);
if(second.ToString().EndsWith(","))
{
second = new StringBuilder( second.ToString().Substring(0,second.ToString().LastIndexOf(",")) );
}
string script=FirstScript()+second.ToString()+ThirdScript();
Page.RegisterStartupScript("MoreSpell",script);
}
FirstScript
SecondScript
ThirdScript
Web Form Designer generated code
}
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.TextBox TextBox3;
protected Telerik.WebControls.RadSpell RadSpell1;
StringBuilder second = new StringBuilder();
private void Page_Load(object sender, System.EventArgs e)
{
SecondScript(this);
if(second.ToString().EndsWith(","))
{
second = new StringBuilder( second.ToString().Substring(0,second.ToString().LastIndexOf(",")) );
}
string script=FirstScript()+second.ToString()+ThirdScript();
Page.RegisterStartupScript("MoreSpell",script);
}
FirstScript
SecondScript
ThirdScript
Web Form Designer generated code
}