不能设置property 'value'javascript中的null
Cannot set property 'value' of null in javascript
我得到以下错误"不能设置属性'值'为null"在javascript命名为"item_pricecataglog.js",以下代码行
document.getElementById('ctl00_ContentPlaceHolder1_ctl00_hdn_returnboolvalue').value = 'true';
我认为这是因为我的应用程序没有在网页或控件中找到相应的元素。
奇怪的是,元素"hdn_returnboolvalue"是在web控件中声明的,从这个Java脚本被引用。下面是我的web控件
的代码片段<%@ control language="C#" autoeventwireup="true" CodeBehind="EstimateProductcatalogueBind.ascx.cs" Inherits="ePrint.usercontrol.ProductCatalogue.EstimateProductcatalogueBind" %>
<script type="text/javascript" src="<%=strSitepath %>js/item/item_pricecatalog.js"
language="javascript"></script>
<div>
<asp:HiddenField ID="hdn_kitavailibility" runat="server" Value="0" />
<asp:HiddenField ID="hdn_returnboolvalue" runat="server" Value="" />
</div>
上面的控件是在名为"common_popup"的aspx页面弹出。我已经将控件添加到"ContentPlaceHolder1",这是在弹出式aspx页面中声明的。
<%@ page language="C#" masterpagefile="~/Templates/popUpMasterPage.master" autoeventwireup="true" CodeBehind="common_popup.aspx.cs" Inherits="ePrint.common.common_popup" title="Untitled Page" enableviewstatemac="false" enableEventValidation="false" theme="Theme1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<script type="text/javascript" language="javascript" src="<%=strSitepath %>js/Item/general.js?VN='<%=VersionNumber%>'"></script>
<div>
<UC:callClass ID="usrCallclass" runat="server" />
</div>
<div>
<asp:PlaceHolder ID="plhDiv" runat="server"></asp:PlaceHolder>
</div>
</asp:Content>
下面是c#代码片段,我从这里添加控件到这个页面
UserControl userControl37 = (UserControl)base.LoadControl("~/usercontrol/ProductCatalogue/EstimateProductcatalogueBind.ascx");
this.plhDiv.Controls.Add(userControl37);
我认为正确的代码应该是(注意id的变化):
document.getElementById('ContentPlaceHolder1_PriceCatalog_hdn_returnboolvalue').value = 'true';
相关文章:
- html+javascript:如何在某些条件下禁用dropdownlist中的null选项
- 什么是 ClojureScript 类似地将不存在的对象值设置为 JavaScript 中的 null
- 从aspx.cs页面获取jquery post中的Null响应而不是json
- 失败:切换弹出窗口时,条目中的null值:name=null错误
- JavaScript 中的 null 或未定义检查
- JavaScript 检测字符串中的 NULL 值
- 我在哪里删除forEach循环/函数中的null元素
- Javascript中的Null合并
- 删除、忽略或阻止IE中字符串中的null字符
- 处理Rally数据存储中的null异常
- 删除$.ajaxPOST的javascript中的null值
- 如何将ruby中的NULL打印到javascript中
- ES6/2015中的null安全属性访问(和条件赋值)
- 不能设置property 'value'javascript中的null
- 不能读取属性'style'动态HTML代码中的null
- 不能设置属性'src'JavaScript中的null
- JavaScript有类似于c#中的null传播操作吗?
- 未捕获的类型错误:不能设置属性'innerHTML'ajax中的null
- 不能读取属性'copycode.js中的null
- 未捕获的类型错误:不能设置属性'innerHTML'在recaptcha_ajax.js中的null