2011-01-05 63 views
1

我有一个问题:我不知道发生了什么,但突然我的Home.aspx.cs没有看到我的runat="server"控件从Home.aspx。下面是从Home.aspx一些代码:我的aspx.cs没有看到我的runat =“服务器”控件

<%@ 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> 

在我Home.aspx.cs,我得到的错误:“这个名字ascuns不会在当前的背景下存在”

回答

1

@Page指令的Inherits属性是错误的。它应该是Inherits="Home"而不是Inherits="_Default"

请记住,ASP.NET服务器不使用CodeFile属性,只能通过Visual Studio Solution Explorer阻止.aspx.cs文件混淆文件列表。 ASP.NET服务器使用InheritsClassName属性将页面标记链接到正确的页面类。

0

您可以尝试将隐藏的字段放在BodyContent占位符中并验证吗? 即

< ASP:内容ID = “HeaderContent” RUNAT = “服务器” ContentPlaceHolderID = “HeadContent”> </ASP:内容> < ASP:内容ID = “的BodyContent” RUNAT = “服务器” ContentPlaceHolderID =“搜索Maincontent “><输入类型=” 隐藏” ID = “ascuns” RUNAT = “服务器”/> </ASP:内容>

由于Home.aspx是一个内容页面,这可能是导致该问题。

希望这会有所帮助!

0

这是我的错误:我有另一个页面后面的代码Home.aspx.cs并生成该错误。

相关问题