Reputation: 11157
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"
Upvotes: 1
Views: 1423
Reputation: 10074
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.
Upvotes: 1
Reputation: 11157
It was my mistake : I had another page that had the code behind Home.aspx.cs and that generated that error .
Upvotes: 0
Reputation: 1166
Can you try placing the hidden field inside the BodyContent placeholder and verify? i.e.
< 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!
Upvotes: 0