0
这是我下面的代码:显示内嵌原因错误背后
<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>
在我后面的代码我想设置trPrice的风格为“显示:内联”在特定的Page_Load - >
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可用于代码 – Andrei
其拼写错误,请尝试txtPrice.Attributes代替:-) – buffjape
@Andrei谢谢!多么愚蠢的错误:/ – ZerOne