【问题标题】:How do i specify CodeFileBaseClass from web.config?如何从 web.config 中指定 CodeFileBaseClass?
【发布时间】:2012-09-01 18:08:07
【问题描述】:

1 正在web.config 中注册一个用户控件 Control

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

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

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

这个错误的修复是你have to remind Visual Studio that the *controlinherits fromControl`:

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

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

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

如何在web.config 中指定CodeFileBaseClass

系列

这个问题是 Stackoverflow 系列中的一个,“模板化用户控件”

【问题讨论】:

  • 出于兴趣,您的问题第一行引用的脚注 #1 在哪里?!

标签: asp.net user-controls templating


【解决方案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"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-10
    • 1970-01-01
    • 1970-01-01
    • 2013-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多