0

我已经使用文本框将英语翻译成古吉拉特语,使用谷歌翻译 java 脚本效果很好,但是当我使用文本框的 ajax 更新面板时它不起作用。

下面是我使用的java脚本。

任何的想法?

谢谢!

<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>
4

1 回答 1

1

当您使用 UpdatePanel 时,您需要在回发后重新初始化脚本:

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

类似问题:当页面在 Gridview Jquery DatePicker 中重新加载 Asp.Net UpdatePanel时,
jquery 脚本工作

于 2012-10-29T08:04:21.287 回答