简体   繁体   English

ASP.NET 控件在后面的代码中无法识别

[英]ASP.NET controls not recognised in code behind

I am getting the我得到

"The name 'ASP.net control' does not exist in the current context" “当前上下文中不存在名称‘ASP.net 控件’”

Error message.错误信息。 Guys, can you please help me find out the cause of this and how to remedy it!各位大侠,能不能帮我看看是什么原因造成的,如何解决!

Am I missing something here??我在这里错过了什么吗?

<%@ Page Title="Amatola Water Activities" Language="C#" MasterPageFile="~/Site.Master"
    AutoEventWireup="true" CodeFile="~/Default.aspx.cs" 
    Inherits="AWActivitiesWeb2.Default" %>

There could be several reasons behind this error, Looking at the <%@ Page %> directive that you shared, you have specified the attribute as CodeFile="~/Default.aspx.cs" Which might be causing this issue because if you specify a CodeFile attribute, the designer.cs file does not regenerates itself.此错误背后可能有多种原因,查看您共享的<%@ Page %>指令,您已将该属性指定为CodeFile="~/Default.aspx.cs"这可能会导致此问题,因为如果您指定CodeFile属性, designer.cs文件不会自行重新生成。 Either you manually specify each control you add into the designer.cs file or you should change the CodeFile attribute to a CodeBehind attribute.您可以手动指定添加到designer.cs文件中的每个控件,或者您应该将CodeFile属性更改为CodeBehind属性。

The other issue could be with the control itself, if you won't specify runat="server" on the attribute then you won't get its reference in the Code Behind.另一个问题可能与控件本身有关,如果您不在属性上指定runat="server" ,那么您将无法在代码隐藏中获得它的引用。

So, Modify your page directive with this line:因此,使用以下行修改您的页面指令:

<%@ Page Title="Amatola Water Activities" Language="C#"
    MasterPageFile="~/Site.Master" AutoEventWireup="true"
    CodeBehind="~/Default.aspx.cs" Inherits="AWActivitiesWeb2.Default" %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM