I have a panel in aspx, but gives error in code Behind(Web Form)

Asked

Viewed 48 times

0

I took a project in aspx to keep and got this on aspx page

<asp:Panel ID="painelTeste" runat="server">

and in code Behind gives error

The name painTeste does not exist in the current context.

What should I do?

Edit1

my context in code Behind.

if (DateTime.Now < dataFaturamento)
{
    painelTeste .Visible = false;
}
else
{
    painelTeste .Visible = true;
}
  • You can post the snippet of the Behind code where it gives the error?

  • If I do that, the mistake goes away: Panel painelTeste = this.FindControl("painelTeste") as Panel;

1 answer

4


Probably this panel was created when the project was running, so no reference was generated for it in the file NomeDaSuaPagina.aspx.designer.cs.

It needs to be a similar reference in the page designer:

protected global::System.Web.UI.WebControls.Panel painelTeste;

Try to add this reference manually, if it doesn’t work delete the control, save the project, restart Visual Studio and write the control again that the designer will be completed correctly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.