jQuery doesn't execute on language change
UPDATE: the problem is that the js is in the UserControl.
I have the following script
<script type="text/javascript">
var jSonUrl = '<%= ResolveUrl("~/Autocomplete/LocalityByPostalCode.ashx") %>';
var txtP开发者_StackOverflowostalCode = '#<%= this.txtPostalCode.ClientID %>';
var txtLocality = '#<%= this.txtLocality.ClientID %>';
$(function () {
var refresh = function () {
var txtPostalCode = '#<%= this.txtPostalCode.ClientID %>';
var txtLocality = '#<%= this.txtLocality.ClientID %>';
//for table row
onEachPageRefresh(txtPostalCode, txtLocality);
}
function onEachPageRefresh(paramPostalCode, paramLocality) {
$(paramPostalCode).blur(function (ev) {
var postalCode = $(this).val();
if (postalCode.length != 4)
return;
$.get(jSonUrl + '?' + postalCode, null, function (responseText, textStatus) {
var txtLoc = $(paramLocality).val('');
if (responseText.match(/\|/)) {
txtLoc.hide();
var all = responseText.split('|');
var select = $('<select />');
for (var i in all) {
select.append('<option>' + all[i] + '</option>');
}
txtLoc.val(all[0]);
txtLoc.parent().append(select);
select.change(function () { $(paramLocality).val($(this).val()) });
} else {
txtLoc.parent().find('select').remove();
txtLoc.show().val(responseText);
}
}, 'text');
});
}
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(function () {
refresh();
});
refresh();
});
</script>
The problem I have is the following: if I come with English it works. If I switch to Hungarian it doesn't work. The thing is that this script works on other pages of the website. The event doesn't fire. The technology is ASP.NET web forms.
UPDATE:
Ok. Here is the update:
I hardcoded the script to the Page, not the UserControl like this
var jSonUrl = '<%= ResolveUrl("~/Autocomplete/LocalityByPostalCode.ashx") %>';
var txtPostalCode = '#MainContent_ucMainBuilding_txtPostalCode';
var txtLocality = '#MainContent_ucMainBuilding_txtLocality';
And it worked. So the problem is that the js is in the UserControl.
Try
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_pageLoaded(function(){
refresh();
});
instead of
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(function () {
refresh();
});
精彩评论