1

1正在注册用户控件Controlweb.config

<configuration>
    <system.web>
       <pages validateRequest="false">
          <controls>
              <add src="~/GenericControls/Toolbar.ascx" 
                    tagName="Toolbar" tagPrefix="Vista" />
          </controls>
       </pages>
    </system.web>
<configuration>

现在,因为我的“用户控件”是 a Control,而不是 a UserControl(为了支持模板),这会导致 Visual Studio 错误:

ASPNET:确保此代码文件中定义的类与“继承”属性相匹配,并且它扩展了正确的基类(例如 Page 或 UserControl)

此错误的修复是您必须提醒 Visual Studio *control inherits fromControl`

<%@ Page language="c#" Inherits="University.AspNet.Index"  
      CodeFile="Index.aspx.cs" CodeFileBaseClass="XXXXXX" %>

具有超级机密CodeFileBaseClass属性。除了我没有使用Page指令外,我在 web-config 中注册了整个站点的控件:

<add src="~/GenericControls/Toolbar.ascx" 
      tagName="Toolbar" tagPrefix="Vista" />

我如何CodeFileBaseClass从内部指定web.config

系列

这个问题是正在进行的 Stackoverflow 系列“模板化用户控件”中的一个:

4

1 回答 1

1

尝试这个:

<system.web>
    <!-- ... -->
    <pages pageBaseType="MyWeb.UI.MyPageBase" />
    <!-- ... -->
</system.web>

另外,请参考以下链接:

http://blogs.msdn.com/b/tom/archive/2008/08/22/known-issues-for-asp-net-with-net-3-5-sp1.aspx

http://forums.asp.net/t/1305800.aspx

建议的解决方法

如果并非所有页面都需要 pageBaseType 类(例如 MyBasePage),您可以将其从 web.config 文件中删除,或者

如果页面确实需要 pageBaseType 值,请修改代码隐藏文件中的类以扩展基本类型。在 filename.aspx.cs 代码隐藏文件中,确保该类继承自 web.config 文件中指定的 pageBaseType(例如,公共部分类 CodeFileClass : MyBasePage 而不是公共部分类 CodeFileClass : System.Web .UI.Page)。

另一种解决方法将允许您将以下属性添加到您的页面指令:

CodeFileBaseClass="System.Web.UI.Page"
于 2012-09-08T09:05:46.213 回答