不工作时使用文本框在AJAX更新面板谷歌翻译器Java脚本 [英] Does not work Google translator java Script used to text box in ajax update panel

查看:106
本文介绍了不工作时使用文本框在AJAX更新面板谷歌翻译器Java脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用文本框的英文翻译使用谷歌翻译Java脚本它的工作原理很好古吉拉特语,但是当我使用AJAX更新面板的文本框中这是行不通的。

下面是Java脚本,我用。

你知道吗?

谢谢!

 <脚本类型=文/ JavaScript的SRC =htt​​ps://www.google.com/jsapi>< / SCRIPT>
    <脚本类型=文/ JavaScript的>
        google.load(元素,1,{
            包:音译
        });
        传播的onLoad(){
            VAR的选择= {
                sourceLanguage:
                google.elements.transliteration.Language code.ENGLISH,
                destinationLanguage:
                google.elements.transliteration.Language code.GUJARATI,

                快速键:Ctrl + G,
                transliterationEnabled:真
            };
            无功控制=
            新google.elements.transliteration.TransliterationControl(选件);
            control.makeTransliteratable(['&其中;%= TextBox1.ClientID%GT;']);
        }
        google.setOnLoadCallback(的onLoad);

        VAR finalString =;
        功能改变(textControl){

            VAR _txtUni $ C $的cname =的document.getElementById('<%= TextBox1.ClientID%>');

            VAR _EnteredString = _txtUni codeName.value;
        }
    < / SCRIPT>

    < ASP:UpdatePanel的ID =Activistupdatepanel=服务器>
                    <的ContentTemplate>
                        < D​​IV>
                            < ASP:按钮的ID =Button1的=服务器文本=按钮的onclick =的button1_Click/>
                            < ASP:文本框ID =TextBox1的=服务器>< / ASP:文本框>
                        < / DIV>
                    < /的ContentTemplate>
                < / ASP:UpdatePanel的>
 

解决方案

当您使用的UpdatePanel,你需要重新初始化后背上后的脚本:

  //也许这还需要在EndRequest内再次
google.load(元素,1,{
    包:音译
});

传播的onLoad(){
    VAR的选择= {
        sourceLanguage:
        google.elements.transliteration.Language code.ENGLISH,
        destinationLanguage:
        google.elements.transliteration.Language code.GUJARATI,

        快速键:Ctrl + G,
        transliterationEnabled:真
    };
    无功控制=
    新google.elements.transliteration.TransliterationControl(选件);
    control.makeTransliteratable(['&其中;%= TextBox1.ClientID%GT;']);
}

//在这里进行第一次初始化时,页面加载
google.setOnLoadCallback(的onLoad);

//这里我们做处理程序UpdatePanel的更新后,
变种PRM = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);

功能InitializeRequest(发件人,参数){
}

    //这个被称为重新初始化后,更新面板更新的谷歌。
功能EndRequest(发件人,参数){
的onLoad();
}
 

类似的问题:
<一href="http://stackoverflow.com/questions/13044180/jquery-script-works-when-page-is-reload/13044264#13044264">jquery脚本的工作时,页面重新加载
<一href="http://stackoverflow.com/questions/3341623/asp-net-updatepanel-in-gridview-jquery-datepicker/3341741#3341741">Asp.Net UpdatePanel的GridView的中jQuery的DatePicker的

I have used the text box for translating English to Gujarati using Google translation java script it works good,but when I used ajax update panel for text box it does not work.

Below is the java script i used.

Any idea?

Thanks!

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
        google.load("elements", "1", {
            packages: "transliteration"
        });
        function onLoad() {
            var options = {
                sourceLanguage:
                google.elements.transliteration.LanguageCode.ENGLISH,
                destinationLanguage:
                google.elements.transliteration.LanguageCode.GUJARATI,

                shortcutKey: 'ctrl+g',
                transliterationEnabled: true
            };
            var control =
            new google.elements.transliteration.TransliterationControl(options);
            control.makeTransliteratable(['<%=TextBox1.ClientID%>']);
        }
        google.setOnLoadCallback(onLoad);

        var finalString = "";
        function Changed(textControl) {

            var _txtUnicodeName = document.getElementById('<%=TextBox1.ClientID%>');

            var _EnteredString = _txtUnicodeName.value;
        }
    </script>

    <asp:UpdatePanel ID="Activistupdatepanel" runat="server">
                    <ContentTemplate>
                        <div>
                            <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
                            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                        </div>
                    </ContentTemplate>
                </asp:UpdatePanel>

解决方案

when you use UpdatePanel you need to re-initialize the script after post backs as:

// maybe this also need to be inside the EndRequest again
google.load("elements", "1", {
    packages: "transliteration"
});

function onLoad() {
    var options = {
        sourceLanguage:
        google.elements.transliteration.LanguageCode.ENGLISH,
        destinationLanguage:
        google.elements.transliteration.LanguageCode.GUJARATI,

        shortcutKey: 'ctrl+g',
        transliterationEnabled: true
    };
    var control =
    new google.elements.transliteration.TransliterationControl(options);
    control.makeTransliteratable(['<%=TextBox1.ClientID%>']);
}

// here you make the first init when page load
google.setOnLoadCallback(onLoad);

// here we make the handlers for after the UpdatePanel update
     var prm = Sys.WebForms.PageRequestManager.getInstance();    
     prm.add_initializeRequest(InitializeRequest);
     prm.add_endRequest(EndRequest);
    
    function InitializeRequest(sender, args) {      
    }
    
    // this is called to re-init the google after update panel updates.
    function EndRequest(sender, args) {
        onLoad();
    }

Similar issues:
jquery script works when page is reload
Asp.Net UpdatePanel in Gridview Jquery DatePicker

这篇关于不工作时使用文本框在AJAX更新面板谷歌翻译器Java脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆