c#
  • jquery
  • asp.net
  • 2011-05-19 52 views 0 likes 
    0

    更新:問題是,js在UserControl中。jQuery不執行語言更改

    我有以下腳本

    <script type="text/javascript"> 
        var jSonUrl = '<%= ResolveUrl("~/Autocomplete/LocalityByPostalCode.ashx") %>'; 
        var txtPostalCode = '#<%= 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> 
    

    我的問題是:如果我跟英文它的工作原理。如果我切換到匈牙利語,它不起作用。問題是這個腳本在網站的其他頁面上工作。該事件不會觸發。該技術是ASP.NET Web表單。

    UPDATE:

    確定。這裏是更新:

    我硬編碼腳本的網頁,而不是在用戶控件這樣

    var jSonUrl = '<%= ResolveUrl("~/Autocomplete/LocalityByPostalCode.ashx") %>'; 
         var txtPostalCode = '#MainContent_ucMainBuilding_txtPostalCode'; 
         var txtLocality = '#MainContent_ucMainBuilding_txtLocality'; 
    

    和它的工作。所以問題在於js在UserControl中。

    +0

    你看到了什麼,當你在匈牙利運行它 - 任何錯誤或異常?什麼不起作用? – Rup 2011-05-19 16:17:48

    +0

    不,我沒有看到任何例外情況,當我更改爲匈牙利語或頁面加載匈牙利語時,唯一發生的事情是它從資源中獲取其他文本。但是這不應該干擾JavaScript。 – 2011-05-19 17:01:57

    +0

    如果我切換到英語,然後回到匈牙利,那麼它的工作原理。 – 2011-05-19 17:54:29

    回答

    0

    嘗試的

    var prm = Sys.WebForms.PageRequestManager.getInstance(); 
    prm.add_pageLoaded(function(){ 
        refresh(); 
    }); 
    

    代替

    var prm = Sys.WebForms.PageRequestManager.getInstance(); 
    prm.add_endRequest(function() { 
        refresh(); 
    }); 
    
    +0

    謝謝,會試試 – 2011-05-19 16:59:43

    +0

    對不起,不起作用。雖然如果我切換到英語,然後回到匈牙利,那麼它的作品。 – 2011-05-19 17:54:06

    +0

    嘗試添加你的'var prm = Sys.WebForms.PageRequestManager.getInstance(); (); prm.add_endRequest(function(){ refresh(); });''outside'$(function(){'如果我明白了,這是你的問題 – 2011-05-19 20:10:09

    相關問題