2
votes

I have the error

"the name 'lblTest' does not exist in the current context"

which is really bugging me out.

ASPX:

<asp:Label ID="lblTest" Visible="false" runat="server" Text="blabal"></asp:Label>

I've placed it in between the content-tags.

code behind:

protected void showResend()
{
    lblTest.Visible = true;
}

What I've tried:

  • Checked spelling
  • Checked that it's the correct namespace
  • Checked that the ASPX and the code-behind pages are propperly linked
  • Made sure that it's runat="server"
  • Deleted the designer.cs page and re-generated it
  • Cleared visual studio cache

And those are all the suggested sollutions I've found on google and SO. Any ideas?

EDIT:

<asp:Label ID="lblTest1" Visible="false" runat="server" Text="blabal"></asp:Label>
<asp:Panel ID="pnlDataList" runat="server" Visible="false" cssclass="draggable"></asp:Panel>

protected void showResend()
{
    //lblTest1.Visible = true;    //Doesn't work
    pnlDataList.Visible = true;   //works fine
}
1
Does your page contain more controls? Do you have same problems with other controls? - labilbe
@johan: did u check the Inherits in aspx page. - Raj
@labilbe Yes, it does. And no, I don't have the same problem. - Johan Hjalmarsson
@Raj No, what do you mean? What should I check? - Johan Hjalmarsson
Please show the entire ASPX and C# file. - CodeCaster

1 Answers

2
votes

The issue is most likely that the control is a child of a parent that blocks the direct access to the control, likely because it is a databound control (like a Repeater or a Listview).

Try moving the label to a line as far up in the DOM tree as possible, like at the start of an asp:Content control. This will ensure that it has no databound parents, and you should be able to access the control.