Make an image size equal the size of a table cell in ASP.NET
<p>I have a table, and one of the cells has dynamically generated content.</p>

<p>I want to have a background image that is exactly the same size as the cell. (ie not tiled, but stretched).</p>

<p>I've found a very good reference <a HREF="http://dsgdev.wordpress.com/2007/03/07/get-table-cell-heights-with-javascript/" rel="nofollow">here</a>, which tells you how to do it in Javascript. This example solves the problem by placing an HTML DIV on the top and the bottom of the cell, then getting Javascript to work out the vertical pixel difference between them.</p>

<p>The biggest problem was that I declare the image as</p>

<pre><code>    &lt;asp:Image ID="imgContentsBackground" CssClass="ContentsBackground" runat="server" ImageUrl="~/Images/MoneyColour3.jpg" /&gt;
</code></pre>

<p>but for some reason ASP.NET arbitrarily renamed the ID from "imgContentsBackground" to "ctl00_imgContentsBackground". Once I hardcoded that ID in the Javascript, the referenced example worked for me.</p>

<p>But I'm thinking - given the rich functionality of ASP.NET, is there a simpler way to determine the size and position of a table cell once the content has been generated, and make an image occupy those dimensions?</p>
