如何从web.config中指定codeFileBaseClass? [英] How do i specify CodeFileBaseClass from web.config?

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

问题描述

1 上午登记的的用户控件控制的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)

ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).

有关这个错误的解决方法是,你要提醒Visual Studio中的*控从 Control`

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>

同时,请参考以下链接:

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文件中删除,或

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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆