Microsoft JScript 运行时错误:“getCities”未定义
我在 UserControll 中使用 RadComboBox 我想将所有城市与 RadComboBox 中的复选框绑定。为此,我编写了如下代码:
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 错误
Microsoft JScript 运行时错误:“getCities”未定义
请告诉我出了什么问题? 提前致谢......
问题已解决。实际上问题出在 MasterPage 中,这就是生成此错误的原因。 感谢大家的支持......
I am Using RadComboBox In UserControll I Want To Bind All The Cities With the CheckBoxes In RadComboBox. For That I Have Written Code As Follows :
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>
And In Code Behind. Following Code:-
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));
}
}
When I Click/CheckBox I am Gettig Error
Microsoft JScript runtime error: 'getCities' is undefined
Please Tell me What's Wrong ??
Thanks In Advance.....
Problem Solved. Actually Problem Was In MasterPage That's Why This Error Was Generated.
Thanks All For The Support....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最好以浏览器看到的方式查看 Javascript 代码,而不是使用嵌入的 ASP 标记。
这些 ASP 标记应转换为字符串;我怀疑问题可能出在这些字符串之一。我不知道
cmbCity.ClientID
或hfGeoLocation.ClientID
的值是什么,但它们可能会导致代码损坏。如果它们包含引号或换行符,那么您的 Javascript 代码将无效。您应该使用浏览器的“查看源代码”功能来查看代码在浏览器中的外观。这可能会告诉您问题所在。
It would be better to see the Javascript code as the browser sees it, rather than with the embedded ASP tags.
These ASP tags should be converted into strings; I suspect the problem is likely to be one of these strings. I don't know what the values of
cmbCity.ClientID
orhfGeoLocation.ClientID
are, but it is possible that they are causing the code to break. If they contain quote marks or line feeds, then your Javascript code will be invalid.You should use the browser's View Source feature to see at how code looks to the browser. This is likely to show you what the problem is.