javascript - 未捕获的类型错误:无法在 asp.net 中设置 null 的属性“值”
问题描述
我收到一个错误 Uncaught TypeError: Cannot set property 'value' of null in asp.net using javascript 当我单击网格视图时。为什么 document.getElementById() 将属性“值”设置为空。这是javascript中的示例代码。我的代码中关于从字段设置值有什么问题吗?
这是后面的代码
protected void gvEmployee_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick", "ViewEmployeeInfo('" + e.Row.Cells[0].Text.Trim() + "','" + e.Row.Cells[1].Text.Trim().Replace("Ñ", "Ñ") + "','" + e.Row.Cells[2].Text.Trim() + "','" + e.Row.Cells[3].Text.Trim() + "')");
}
}
我有 4 个参数需要在 iframe/modal 的 4 个字段中设置一个值。
function ViewEmployeeInfo(field1, field2, field3, field4) {
document.getElementById("ctl00_MainContent1_tbEmployeeID").value = field1;
document.getElementById("ctl00_MainContent1_tbEmployeeName").value = field2;
document.getElementById("ctl00_MainContent1_tbDepartment").value = field3;
document.getElementById("ctl00_MainContent1_tbCompany").value = field4; }
这是html方面
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" >
</asp:ScriptManager>
<div class="setWindow" style="background-image: url('Images/BorderDesign/divBG1.png')">
<div class="setMenu">
<div class="setModuleLink">
</div>
</div>
<div class="setContentUser">
<div class="userInformation">
<div class="settingsTabTitle">
User Setup</div>
<hr />
<div class="MBSGridviewUser" style="width: 45%; position: relative; float: left">
<table border="0">
<tr>
<td colspan="">
<h3>
User Information</h3>
</td>
</tr>
<asp:Literal ID="Literal2" runat="server"></asp:Literal>
<tr>
<td align="left">
Employee Name:
</td>
<td align="left" class="style2">
<asp:TextBox ID="tbEmployeeName" runat="server" Width="209px" onfocus="this.blur()"></asp:TextBox>
<input id="EmployeeNameLookUp" class="buttonF" type="button" value="View" onclick="ViewModal();" />
</td>
</tr>
<tr>
<td align="left">
Employee ID:
</td>
<td align="left" class="style2">
<asp:TextBox ID="tbEmployeeID" runat="server" Width="209px" onfocus="this.blur()"></asp:TextBox>
</td>
</tr>
<tr>
<td align="left">
User ID:
</td>
<td align="left" class="style2">
<asp:TextBox ID="tbUserID" runat="server" Width="209px"></asp:TextBox>
</td>
</tr>
</tr>--%>
<tr>
<td align="left">
Company:
</td>
<td align="left" class="style2">
<asp:TextBox ID="tbCompany" runat="server" Width="209px" onfocus="this.blur()"></asp:TextBox>
</td>
</tr>
<tr>
<td align="left">
Department:
</td>
<td align="left" class="style2">
<asp:TextBox ID="tbDepartment" runat="server" Width="209px" onfocus="this.blur()"></asp:TextBox>
</td>
</tr>
<tr>
<td align="left">
Email Address:
</td>
<td align="left" class="style2">
<asp:TextBox ID="tbEmailAdd" runat="server" Width="209px"></asp:TextBox>
</td>
</tr>
</table>
解决方案
推荐阅读
- php - 将作曲家启用站点部署到生产时出现 Guzzle 401 错误?
- rest - Sharepoint Foundation REST 接口,更新对象失败
- ruby-on-rails - 外键的 ActiveRecord has_many 和 belongs_to 实现
- r - 通过 R 中的弹出窗口输入 Csv 文件
- python - 将 Python Pandas 行翻译成 R:
- python - 如何只记录某个级别名称 python 日志记录
- r - 如何恢复未保存的 R 代码?
- ios - 从另一个视图控制器动态更改视图控制器的主题而无需重新加载
- php - 使用 valet (cretueusebiu/valet-windows) 在本地 Windows 计算机上安装 wordpress 时出现致命错误
- asp.net - 由于中继器内背景图像的内联设置,ASP.NET 页面加载触发两次