Asp.net implements spelling check using the Google Interface

Source: Internet
Author: User

Key words: spelling check SpellCheck English spelling check
When developing a foreign outsourcing project, the customer needs to input words in the text box and check the spelling before saving the project. If a word error is found, the user can be reminded to correct the problem, therefore, in combination with the reference of a variety of solutions, choose a free solution, Google an API interface, https://www.google.com/tbPRoxy/spell? Lang =, this interface provides spelling checks in multiple languages and returns similar words. Fortunately, an open-source package named googiespell was found online, therefore, after simple packaging, a spelling check widget is made, which is easy to use.
Implementation Principle
In. net page, before the submit button is submitted, send the text box content of the page to the Google interface in the form of Ajax and proxy class, the interface will return the spelling result, if there is no spelling Error, the browser will directly submit the operation. If there is an Error, a Spell Check Error dialog box will pop up, prompting the user to modify it. Click "yes" to return to the page for modification, click "No" to ignore spelling mistakes and submit them directly.
Code sharing
User Control Shouji138.com. SpellValid. ascx
This file encapsulates the input box effects of error messages and some operation code for the submit button.
<% @ Control Language = "C #" AutoEventWireup = "true" Codebehind = "Shouji138.com. SpellValid. ascx. cs"
Inherits = "SpellCheck. Shouji138_com_SpellValid" %>
<Script type = "text/javascript">
Var googie5 = new GoogieSpellMultiple ("/googiespell/", "/googiespell/sendSpellReq. aspx? Lang = ");
// New menu item "Add"
Var add_checker = function (elm ){
Return true;
};
Var add_item = function (elm, current_googie ){
Googie5.ignoreAll (elm );
};
// Googie5.appendNewMenuItem ("Add", add_item, add_checker );
Var fn_no_more_errors = function (e ){
// Alert (no more errros );
Passcheck = true;
}
Googie5.setDependent ();
Googie5.setCustomAjaxError (function (req ){
// Alert (error );
});
Googie5.useCloseButtons ();
Googie5.noMoreErrorsCallback (fn_no_more_errors );
Googie5.setSpellContainer ("global_spell_container ");
// Googie5.decorateTextareas (textbox, "El", "t ");
// Getstatespan2 ();
Var passcheck = false;
Var savebutton = null;
Var waiti = 0;
Function CheckSpell (obj ){
If (typeof (Page_ClientValidate) = function ){
If (Page_ClientValidate () = false ){
Return false;
}
}
Savebutton = obj;
If (googie5.noErrorsFound () | passcheck ){
// Alert ("CheckSpell OK ");
Return true;
}
// Alert (document. getElementById ("global_spell_container"). innerHTML );
If (document. getElementById ("okclickspan "))
InvokeClick (document. getElementById ("okclickspan "))
SetTimeout ("WaitSavetate ()", 1000 );
Return false;
}
Function ToDoNext (){


If (savebutton. href ){
Var href = savebutton. href. replace ("Javascript :","");
Href = unescape (href );
// Alert (href );
Eval (href );
}
Else
{
_ DoPostBack (savebutton. id ,"");
Return true;
}
}
Function WaitSavetate (){
If (waiti> 100 ){
Waiti = 0;
Return;
}
Waiti ++;
// Document. getElementById ("statespan"). innerHTML = "waiting:" + waiti + "" + googie5.noErrorsFound ();
If (passcheck | googie5.noErrorsFound ()){
// Alert ("pass ");
// InvokeClick (savebutton );
ToDoNext ();

// _ DoPostBack (savebutton. id ,);
}
Else {
If (googie5.getState () = "checking_spell "){
SetTimeout ("WaitSavetate ()", 500 );
}
Else {
Showdivspellcheckerror ();
}
}
}
Function getText1value (){
Alert (document. getElementById (textbox). value );
}
Function invokeClick (element ){
If (element. click) element. click ();
Else if (element. fireEvent) element. fireEvent (onclick );
Else if (document. createEvent ){
Var evt = document. createEvent ("MouseEvents ");
Evt. initEvent ("click", true, true );
Element. dispatchEvent (evt );
}
}
</Script>
Asp.net Source: http://code.knowsky.com/down.asp? Typeid = 2
<Script type = "text/javascript">
Function closedivspellcheckerror (){
Document. getElementById ("divspellcheckerror"). style. display = "none ";
}
Function showdivspellcheckerror (){
&

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.