“The name xxx does not exist in the current context” after adding LoginView
Question
I have a simple, single-page in ASP.NET (C#). I wanted to add login control, so I just added LoginView as follows:
<form id="form1" runat="server">
<asp:LoginView ID="LoginView1" runat="server">
<AnonymousTemplate>
<asp:Login ID="Login1" runat="server">
</asp:Login>
</AnonymousTemplate>
<LoggedInTemplate>
... here I put all the page elements (buttons, grid views, etc.)
</LoggedInTemplate>
</asp:LoginView>
</form>
When I run my project I get compilation errors in my code-behing file:
The name xxxx does not exist in the current context
What am I doing wrong? I'm new in ASP.NET, so probably it is some stupid mistake I make.
Solution 2
I have found this as the solution for my problem. I can use this, to get my objects.
Label Label1 = (Label)LoginView1.FindControl("Label1");
I don't know if it is the only solution. Maybe someone has better.
OTHER TIPS
There are several possible causes of this problem.
One is that you have a backup copy of this same file somewhere in your project.
Another is that two different ASPX files are using the same CS file for code-behind.
A third is that you forgot to include System.Web or some other file you need.
Hope one of these helps!
My solution: This is a case copy project of web-application. solution: Right click project in visualstudio choose "Convert to web application". this is a good solution