Friday, May 28, 2010

Why is my ASP:Image not accessible from the vb?

I just figured this out. Figured it might bite someone else someday.

Given this code in an aspx file:

<table width="100%">
<tr>
<td class="normaltxt10" colSpan="50">
<!--
<asp:DataGrid id="dgImage" runat="server" ShowHeader="False"
AutoGenerateColumns="False" TabIndex="5">
<Columns>
<asp:BoundColumn Visible="False" DataField="file"></asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
-->
<asp:Image ID="screenShotImage" Runat="server"></asp:Image>
<!--
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
-->
</td>
</tr>
</table>


Why would screenShotImage be not accessible in the vb code behind?

Answer: because it's in the commented out DataGrid, and in my case, dgImage wasn't referenced at all in the vb.
Removing the commented out DataGrid will fix this.
Like so:

<table width="100%">
<tr>
<td class="normaltxt10" colSpan="50">
<asp:Image ID="screenShotImage" Runat="server"></asp:Image>
</td>
</tr>
</table>

This is stupid in my opinion, but whatever. Now we know.