【发布时间】:2016-04-26 03:55:38
【问题描述】:
这是我的以下代码:
<tr id="trPrice" style = "display:none;">
<td colspan=2></td>
<td><b>Price:</b></td>
<td><asp:textbox id="txtPrice" runat="server" style = "border-style:none"></asp:textbox></td>
</tr>
在我后面的代码中,我想在特定的 page_load 处将 trPrice 的样式设置为“display:inline” ->
Protected WithEvents txtPrice As System.Web.UI.WebControls.TextBox
' In Page_Load function:
If type = 3 Or type = 4 Then
trPrice.Attributes.Add("style", "display:inline")
End If
但是出现这个错误:
对象引用未设置为对象的实例。
说明:在执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
异常详细信息:System.NullReferenceException:对象引用未设置为对象的实例。
【问题讨论】:
-
您需要
runat="server"才能将此tr用于代码隐藏 -
这是一个拼写错误,请尝试 txtPrice.Attributes :-)
-
@Andrei 谢谢!多么愚蠢的错误:/