Google transliteration not working in update panel

810 views Asked by At
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">


    $(document).ready(function () {
        google.load("elements", "1", {
            packages: "transliteration"
        });

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

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

</script>

    // update panel with button to make post back
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" />
                    <asp:Label ID="Label1" Text="text" runat="server" />
                    <asp:Button ID="Button1" Text="Postback" runat="server" OnClick="Button1_Click" />
                </ContentTemplate>
            </asp:UpdatePanel>

I already tried this solution Does not work Google translator java Script used to text box in ajax update panel . If I place google transliteration code from outside the page ready then it works fine but after post back it does not work. If I place code inside the page ready event then page is not loading. please help me.

1

There are 1 answers

0
phuc.nx On

you use: add

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:TextBox ID="TextBox1" runat="server" />
                <asp:Label ID="Label1" Text="text" runat="server" />
                <asp:Button ID="Button1" Text="Postback" runat="server" OnClick="Button1_Click" />
            </ContentTemplate>
<Triggers>
        <asp:PostBackTrigger ControlID="Button1" />
</Triggers>
        </asp:UpdatePanel>