locked
findcontrol in ascx issue RRS feed

  • Question

  • User-125499312 posted

    i have a web control here is my code

    <asp:TableCell ID="tdGiftRegistryVendorItemShippingBoxLabel1" runat="server" CssClass="LabelTextSmall2" />

    in code behind

    CType(Page.FindControl("tdGiftRegistryVendorItemShippingBoxLabel1"), TableCell).Text = Now.ToLongTimeString

    when i try it i get object reference not set to an instance of an object

    thx for ur help

    Monday, October 15, 2018 6:34 PM

All replies

  • User839733648 posted

    Hi yzidell,

    You are getting Object reference not set to an instance of an object because TableCell is NULL or NOTHING.

    It is always good practice to check for NULL or NOTHING when you are dealing with objects.

    Besides, it seems that you want to set the TableCell's Text as NowTime according to your code,. 

    I suggest that you could just find the id of TableCell and set the Text of it as the following code.

     tdGiftRegistryVendorItemShippingBoxLabel1.Text = Now.ToLongTimeString

    result:

    Best Regards,

    Jenifer

    Tuesday, October 16, 2018 6:16 AM