“名称 xxx 在当前上下文中不存在”添加LoginView后
我有一个简单的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
导致此问题的可能原因有多种。
一是您有一个备份副本项目中某处的同一个文件。
另一个问题是两个不同的 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!
我发现 这 作为我的问题的解决方案。我可以用它来获取我的对象。
我不知道这是否是唯一的解决方案。也许有人有更好的。
I have found this as the solution for my problem. I can use this, to get my objects.
I don't know if it is the only solution. Maybe someone has better.
我的解决方案:
这是一个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