Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

i1 am registering a user control Control in web.config:

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

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

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).

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

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" />

How do i specify CodeFileBaseClass from within web.config?

Series

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
543 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try this:

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

Also, Refer below links:

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

Suggested Workarounds:

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

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"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...