views:

623

answers:

2

Hi,

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.

A: 

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!

Matthew Jones
Non of those. My page was working good, so the headers are ok. I didn't manipulate with the files. I just embraced my controls on the main page (Default.aspx) with LoginView control.
Lukasz Lysik
A: 

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.

Lukasz Lysik