I have a simple asp:Label control on a web page. In the Page_Load event I am conditionally populating the label with a warning. Simple, right? This used to work but now I get an error saying the control is null.
The control declaration:
<table width="100%">
<tr>
<td align="right">
<asp:Label ID="lblWarningLabel" runat="server" Enabled="False"></asp:Label>
</td>
</tr>
</table>
The code-behind where lblWarningLabel is found to be null:
if (sServerName.Contains("Staging") || sServerName.Contains("Test"))
{
Int32 iIndex = sServerName.IndexOf("/");
lblWarningLabel.Text = "Warning: You are working on the " + sServerName.Substring(iIndex + 1) + " server!";
lblWarningLabel.CssClass = "WarningLabel";
lblWarningLabel.Enabled = true;
}
I have researched this and I have found some posters saying that their user control was null or that they were trying to create the control dynamically, neither of which pertain here. I am not using Resharper but since the last time I looked at this program, I have installed some Productivity Tools via NuGet.
Thanks for your help.
Update: I should add that another asp:Label control on the same page is working as expected. I also changed "False" to "false" and then removed the Enabled clause all together, but there was no change in behavior.