1

我在 ASP.NET (C#) 中有一个简单的单页。我想添加登录控件,所以我只是添加了LoginView,如下所示:

<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>

当我运行我的项目时,我的代码行为文件中出现编译错误:

The name xxxx does not exist in the current context

我究竟做错了什么?我是 ASP.NET 的新手,所以这可能是我犯的一些愚蠢的错误。

4

3 回答 3

2

这个问题有几个可能的原因。

一个是您在项目的某处有相同文件的备份副本。

另一个是两个不同的 ASPX 文件使用相同的 CS 文件进行代码隐藏。

第三是您忘记包含 System.Web 或您需要的其他文件。

希望其中之一有帮助!

于 2009-09-24T15:45:11.920 回答
1

我发现是我的问题的解决方案。我可以使用它来获取我的对象。

Label Label1 = (Label)LoginView1.FindControl("Label1");

我不知道这是否是唯一的解决方案。也许有人有更好的。

于 2009-09-24T16:00:17.987 回答
1

我的解决方案:这是一个 Web 应用程序的案例复制项目。解决方案:在visualstudio中右键单击项目选择“转换为Web应用程序”。这是一个很好的解决方案

于 2013-05-07T03:28:30.333 回答