“名称 xxx 在当前上下文中不存在”添加LoginView后

发布于 2024-08-05 22:04:21 字数 658 浏览 4 评论 0原文

我有一个简单的 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 的新手,所以这可能是我犯的一些愚蠢的错误。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

半山落雨半山空 2024-08-12 22:04:21

导致此问题的可能原因有多种。

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

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

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

希望其中之一有帮助!

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!

倾其所爱 2024-08-12 22:04:21

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

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

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

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.

说好的呢 2024-08-12 22:04:21

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文