Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 338921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:28:28+00:00 2026-05-12T10:28:28+00:00

Potentially embarrassing question, but there is obviously something I’m missing that I want/need to

  • 0

Potentially embarrassing question, but there is obviously something I’m missing that I want/need to know.

I expect the following code to create a new table row with new cells to be rendered later. And that’s what it does … as you would expect.

using (TableRow tr = new TableRow())
{
    using (TableCell td = new TableCell())
    {
        td.Text = "Column A";
        tr.Cells.Add(td);
    }
    using (TableCell td = new TableCell())
    {
        td.Text = "Column B";
        tr.Cells.Add(td);
    }
    tbl.Rows.Add(tr);
}

But …. but aren’t the TDs created in the using statements invalidated once they go out of the ‘using’ scope? Wouldn’t the TD objects referenced by the row now be invalid and shouldn’t the row fail when it attempts to use them? The same could be said for the TR when it’s rendered by the ‘tbl’ object.

Do I not understand dispose?

Do I not understand using?

Is TableRow.Cells.Add() actually doing a deep copy not just a ref ptr copy?

Can the TableCell actually be used after it’s disposed?

What gives?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T10:28:28+00:00Added an answer on May 12, 2026 at 10:28 am

    All the “using” block does is ensure that the object’s “Dispose” method is called at the end of the block. Objects can still be used accessed after they are disposed, but it’s up to their implementation of the “Dispose” method to know if anything bad will happen if this is done.

    In this case, it doesn’t look like the “Dispose” method on TableRow & TableCell does anything that prevents them from being used in the future. That’s why you don’t have any problems.

    Since you do want the objects to be used in the future, you shouldn’t put them in “using” blocks at all. The parent page object should dispose of the controls at the end of the page lifecycle.

    Edit:
    I made a test server control and put a breakpoint in its “Dispose” event. Here’s the stack trace that shows .Net calling dispose for you. You can use Reflector to look at the code in more detail.

    at TestControl.Dispose() in D:\TestControl.cs:line 25  
    at System.Web.UI.Control.UnloadRecursive(Boolean dispose)   
    at System.Web.UI.Control.UnloadRecursive(Boolean dispose)   
    at System.Web.UI.Control.UnloadRecursive(Boolean dispose)  
    at System.Web.UI.Control.UnloadRecursive(Boolean dispose) 
    at System.Web.UI.Page.UnloadRecursive(Boolean dispose)  
    at System.Web.UI.Page.ProcessRequestCleanup()   
    at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)   
    at System.Web.UI.Page.ProcessRequest()   
    at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)   
    at System.Web.UI.Page.ProcessRequest(HttpContext context)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may turn out to be an embarrassingly stupid question, but better than potentially
Assume there are potentially expensive operations to be performed in setup or teardown that
Forgive me for a potentially silly question here, but in other programming languages (scripting
I have potentially large files that need to be sorted by 1-n keys. Some
Potentially a very silly question-- Is it possible to customize Akka/Scala actors such that
Sorry in advance for a potentially dumb newbie question, but here goes. I am
Ok this is potentially a noob question but here goes. Is it possible to
Need to execute potentially dangerous binary file and want to deny access any hardware.
Given a potentially huge integer value (in C# string format), I want to be
How to find potentially duplicate files in a given directory? Is there some existing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.