0
votes

this is my following code:

<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>

And in my Code behind I want to set the style of the trPrice to "display:inline" at a specific 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

But this error occurs:

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

1
You need runat="server" to make this tr available for code-behind - Andrei
its a spelling mistake, try txtPrice.Attributes instead :-) - user1023602
@Andrei thanks! what a stupid mistake :/ - ZerOne

1 Answers

1
votes

You need to make it runat="server", then visual studio will add this to the designer.vb file:

Protected WithEvents trPrice As Global.System.Web.UI.HtmlControls.HtmlTableRow

and it will be initialized in Page_Load.