简体   繁体   中英

my aspx.cs doesn't see my runat=“server” controls

I have a problem: I don't know what happened, but suddenly my Home.aspx.cs doesn't see my runat="server" controls from Home.aspx . Here is some code from Home.aspx :

<%@ Page Title="Home Page"
    Language="C#"
    MasterPageFile="~/Site.master"
    AutoEventWireup="true"
    CodeFile="Home.aspx.cs" Inherits="_Default" %>

<asp:Content ID="HeaderContent"
    runat="server"
    ContentPlaceHolderID="HeadContent">
</asp:Content>

<input type="hidden"
    id="ascuns" runat="server" />

<asp:Content ID="BodyContent" 
    runat="server"
    ContentPlaceHolderID="MainContent">
</asp:Content>

And in my Home.aspx.cs , I get the error: "The name ascuns does not exist in the current context"

The Inherits attribute of your @Page directive is wrong. It should read Inherits="Home" instead of Inherits="_Default" .

Keep in mind that the CodeFile attribute is not used by the ASP.NET server, only by the Visual Studio Solution Explorer to prevent the .aspx.cs files from cluttering up the file list. The ASP.NET server uses either the Inherits or the ClassName attribute to link the page markup to the right page class.

Can you try placing the hidden field inside the BodyContent placeholder and verify? ie

< asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> < /asp:Content> < asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> < input type="hidden" id="ascuns" runat="server" /> < /asp:Content>

Since the Home.aspx is a content page, that might be causing the issue.

Hope this helps!

这是我的错误:我还有另一个页面,其中包含Home.aspx.cs背后的代码,并产生了该错误。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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