How to enable Google Transliteration for multiple dynamic Textboxes (ASP.Net)

佐手、 提交于 2019-12-06 13:05:27

Use RegisterStartupScript. RegisterStartupScript will be be executed after page is loaded completely.

function EnableTransalation(ctrlId) {
    //Script Starts here

    // Load the Google Transliterate API
    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
        };

        // Create an instance on TransliterationControl with the required
        // options.
        var control =
        new google.elements.transliteration.TransliterationControl(options);

        // Enable transliteration in the textbox with id
        // 'transliterateTextarea'.
        control.makeTransliteratable(["'" + ctrlId + "'"]);
    }
    google.setOnLoadCallback(onLoad);

    //End here
}

In the code behind,

protected override void OnPreRender(EventArgs e)
{
  Page.ClientScript.RegisterStartupScript(GetType(), "EnableTransalation", "EnableTransalation('" + ctrl.ClientID + "')", true);
}

First you have to set all text box class name as hindiFont.

Use this Code:

google.load("elements", "1", {
    packages: "transliteration"
});

function onLoad() {
    var options = {
        sourceLanguage: [google.elements.transliteration.LanguageCode.ENGLISH],
        destinationLanguage: [google.elements.transliteration.LanguageCode.HINDI],
        transliterationEnabled: true,
        shortcutKey: 'ctrl+g'

    };

    var control = new google.elements.transliteration.TransliterationControl(options);

    $('.hindiFont').each(function(){
        var id = this.id;
        control.makeTransliteratable([id]);
    })
}
google.setOnLoadCallback(onLoad);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!