本文介绍了如何从web.config中指定codeFileBaseClass?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我上午登记的的用户控件控制的web.config

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

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

Now, because my "user control" is a Control, rather than a UserControl (in order to support templating), this causes the Visual Studio error:

ASPNET:请确保此code文件中定义的类继承属性匹配,而它扩展了正确的基类(例如Page或UserControl)

有关这个错误的解决方法是,你:

The fix for this bug is that you have to remind Visual Studio that the *controlinherits fromControl`:

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

与超级秘密 codeFileBaseClass 属性。我现在不使用网页指令,我注册控站点范围在网络配置:

with the super-secret CodeFileBaseClass attribute. Except i'm not using a Page directive, i'm registering the control site-wide in web-config:

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

我如何从 web.config文件中指定 codeFileBaseClass

这个问题是一个在正在进行的系列#1,模板的用户控件

This question is one in the ongoing Stackoverflow series, "Templating user controls":







  • How to add a Templating to a UserControl?
  • How to inherit from Control, rather than UserControl?
  • UserControl has IsPostBack, but Control does not
  • UserControl does not have public property named ContentTemplate
  • How do i specify CodeFileBaseClass from web.config?

推荐答案

试试这个:

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

同时,请参考以下链接:

建议的解决方法

如果不需要所有页面的pageBaseType类(例如,MyBasePage),你可以从web.config文件中删除,或

If the pageBaseType class (for example, MyBasePage) is not needed for all pages, you can remove it from the web.config file, or

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

Where pages do require the pageBaseType value, modify the classes in the code-behind files to extend the base type. In the filename.aspx.cs code-behind file, make sure that the class inherits from the pageBaseType that is specified in the web.config file (for example, public partial class CodeFileClass : MyBasePage instead of public partial class CodeFileClass : System.Web.UI.Page).

这是另一种解决方法可以让你将以下属性添加到您的页面指令:

An alternative workaround will allow you to add the following attribute to your page directive:

CodeFileBaseClass="System.Web.UI.Page"

这篇关于如何从web.config中指定codeFileBaseClass?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 09:31