2011-07-25 51 views
0

我在用戶控件中使用RadComboBox我想用RadComboBox中的複選框來綁定所有城市。對於我寫的代碼如下:Microsoft JScript運行時錯誤:'getCities'未定義

FOR ASPX: -

<script type="text/javascript"> 
function getItemCheckBox(item) { 
    debugger; 
    //Get the 'div' representing the current RadComboBox Item. 
    var itemDiv = item.get_element(); 

    //Get the collection of all 'input' elements in the 'div' (which are contained in the Item). 
    var inputs = itemDiv.getElementsByTagName("input"); 

    for (var inputIndex = 0; inputIndex < inputs.length; inputIndex++) { 
     var input = inputs[inputIndex]; 

     //Check the type of the current 'input' element. 
     if (input.type == "checkbox") { 
      return input; 
     } 
    } 

    return null; 
} 
function check() { 
    debugger; 
    alert("hello"); 
} 
function getCities() { 

    var combo = $find("<%= cmbCity.ClientID %>"); 
    var hdnAddressType = document.getElementById("<%= hfGeoLocation.ClientID %>"); 
    var items = combo.get_items(); 
    var selectedItemsTexts = ""; 
    var selectedItemsValues = ""; 
    var itemsCount = items.get_count(); 
    for (var itemIndex = 0; itemIndex < itemsCount; itemIndex++) { 
     var item = items.getItem(itemIndex); 

     var checkbox = getItemCheckBox(item); 

     //Check whether the Item's CheckBox) is checked. 
     if (checkbox.checked) { 
      selectedItemsTexts += item.get_text() + ", "; 
      selectedItemsValues += item.get_value() + ","; 
     } 
    } 

    hdnAddressType.value = selectedItemsValues; 

    selectedItemsTexts = selectedItemsTexts.substring(0, selectedItemsTexts.length - 2); 
    selectedItemsValues = selectedItemsValues.substring(0, selectedItemsValues.length - 2); 

    //Set the text of the RadComboBox with the texts of the selected Items, separated by ','. 
    combo.set_text(selectedItemsTexts); 

    //Set the comboValue hidden field value with values of the selected Items, separated by ','. 
    combo.set_value(selectedItemsValues); 

    //Clear the selection that RadComboBox has made internally. 
    if (selectedItemsValues == "") { 
     combo.clearSelection(); 
    } 
} 
</script> 

<div> 
     <telerik:RadComboBox ID="cmbCity" runat="server" Height="200px" ExpandDirection="Up" 
        Width="130px"> 
        <ItemTemplate> 
         <div id="chk"> 
          <asp:CheckBox ID="chkCity" runat="server" onclick="getCities();" Text='<%#Eval("CityName")%>' /> 
         </div> 
        </ItemTemplate> 
    </telerik:RadComboBox> 
    <asp:HiddenField ID="hfGeoLocation" runat="server" /> 
</div> 

並在代碼後面。下面的代碼: -

protected void Page_Load(object sender, EventArgs e) 
{ 
    List<usp_SelectCmbCityResult> lstCity = null; 
    if (!Page.IsPostBack) 
    { 
     lstCity = new CityDomain().SelectCmbCity(); 
     cmbCity.DataSource = lstCity; 
     cmbCity.DataValueField = "CityName"; 
     cmbCity.DataTextField = "CityName"; 
     cmbCity.DataBind(); 
     MenUs.Common.Common.BindRadioButtonList(ref rbtnOrientation, typeof(MenUs.Common.Enums.Orientation)); 
     MenUs.Common.Common.BindRadioButtonList(ref rbtnTargetGender, typeof(MenUs.Common.Enums.TargetGender)); 
     MenUs.Common.Common.BindRadioButtonList(ref rbtnTargetMarital, typeof(MenUs.Common.Enums.TargetMaritalStatus)); 
    } 
} 

當我點擊/複選框我Gettig錯誤

微軟JScript運行時錯誤: 'getCities' 未定義

請告訴我什麼是錯的? 感謝提前.....


問題解決。其實問題出在MasterPage上,這就是爲什麼會產生這個錯誤。 感謝所有的支持....

+0

你在IIS或ASP.NET開發服務器中遇到這個錯誤嗎? –

+0

@RăzvanPanda:在ASP.NET開發服務器上Sir –

+0

script代碼在代碼中關閉了嗎? –

回答

0

它會更好地看到JavaScript代碼,因爲瀏覽器看到它,而不是嵌入式ASP標籤。

這些ASP標籤應該被轉換成字符串;我懷疑問題可能是這些字符串之一。我不知道cmbCity.ClientIDhfGeoLocation.ClientID的值是什麼,但它們可能導致代碼中斷。如果它們包含引號或換行符,那麼您的Javascript代碼將會失效。

您應該使用瀏覽器的「查看源代碼」功能來查看代碼在瀏覽器中的外觀。這可能會告訴你問題是什麼。

相關問題