Google API-translation, background C # Call front-end JS Code, Asp.net back-end call JS Code

Source: Internet
Author: User

 

 

 

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 );
}
}

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.