我使用文本框将英语翻译成古吉拉特语使用谷歌翻译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>
答案 0 :(得分: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();
}
类似问题:
jquery script works when page is reload
Asp.Net UpdatePanel in Gridview Jquery DatePicker