Previous paragraph:
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. cs" inherits = "_ default" %>
<! 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>
<Title> simple translator </title>
<SCRIPT type = "text/JavaScript" src = "https://www.google.com/jsapi? Key = AIzaSyBn_f4BjfZU1AoJxqe5Bs-Bd_j-HMweksA "> </SCRIPT>
</Head>
<SCRIPT type = "text/JavaScript">
Google. Load ("language", "1 ");
Function translate_for_me (){
VaR text = Document. getelementbyid ("text_box"). value;
Google. Language. Translate (text, 'ch', 'en', callback_function );
}
Function callback_function (result ){
VaR translated = Document. getelementbyid ("Translation ");
If (result. Translation ){
Translated. innerhtml = result. translation;
} Else {
Translated. innerhtml = "no translation result ";
}
}
</SCRIPT>
<Body>
<Form ID = "form1" runat = "server">
<Input type = "text" id = 'text _ box' runat = "server"/>
<Input type = 'button 'onclick = "translate_for_me ()" value = 'translate _ js'/>
<Asp: button id = "button3" runat = "server" text = "translate_c #" onclick = "button3_click"/>
</BR>
<Div id = "Translation"> </div>
</Form>
</Body>
</Html>
Background:
Using system;
Using system. configuration;
Using system. Data;
Using system. LINQ;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. htmlcontrols;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. xml. LINQ;
Public partial class _ default: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
If (! Ispostback ){
}
}
Protected void button3_click (Object sender, eventargs E)
{
Scriptmanager. registerstartupscript (page, this. GetType (), "myscript", "translate_for_me ('ce ');", true );
}
}