Solved

The base class includes the field 'xxx', but its type (nnn.yyy) is not compatible with the type of control (nnn.yyy)

Posted on 2008-06-10
7
1,833 Views
Last Modified: 2012-05-05
I have a class file called Class1.cs that inherits from the WebPart class, located in the App_Code folder.

I have put the following Register tag at the top of my aspx page:

<%@ Register TagPrefix="wp" Namespace="nnn" %>

I have added the following within the HTML of the page:

        <asp:WebPartZone ID="WebPartZone1" runat="server">
        <ZoneTemplate>
            <wp:Class1 id="WebPartId" runat="server" Title="Web Part Example" />
        </ZoneTemplate>

I get a warning in Visual Studio

Warning      1      (path)\WebForm1.aspx:
ASP.NET runtime error: The base class includes the field 'WebPartId', but its type (nnn.Class1) is not compatible with the type of control (nnn.Class1).      

I get the same message when I try to run the web page, but this time as an error.

What am I doing wrong?


0
Comment
Question by:purplesoup
  • 5
  • 2
7 Comments
 
LVL 37

Expert Comment

by:samtran0331
ID: 21750507
This KB article seems to describe your exact issue:
http://support.microsoft.com/kb/919284
0
 

Author Comment

by:purplesoup
ID: 21767823
I've added the batch="false" parameter but I am getting the same error.
0
 

Author Comment

by:purplesoup
ID: 21767975
I have posted files to give an example of the problem.

I think you will still have to add in web parts through Visual Studio to get it to work, but this will show you the source code to use to replicate it.
WebPartWalkthrough1.zip
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 37

Accepted Solution

by:
samtran0331 earned 500 total points
ID: 21769528
I just got a chance to look through your code sample a bit...how comfortable/experienced are you with working with Web Parts and custom controls in general?
Is your sample coming from a tutorial somewhere?
0
 

Author Comment

by:purplesoup
ID: 21792400
I am working through the book web parts in action by Darren Neimke and there is an example of what I am doing here:

(the book website is here http://www.manning.com/neimke/)

The example from the book has the following code for the aspx page

<%@ Register TagPrefix="wp" Namespace="WebPartTests" %>
...
        <asp:WebPartZone ID="WebPartZone1" runat="server">
            <ZoneTemplate>
                <wp:CustomWeatherPart id="CustomWeatherPart1" runat="server" Title="Weather Forecast" />
            </ZoneTemplate>
        </asp:WebPartZone>

here is the class code

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace WebPartTests {

    public class CustomWeatherPart : WebPart {
        public CustomWeatherPart() { }

        enum WeatherType {
            Sunny = 0,
            Rainy = 1,
            Cloudy = 2,
            Unknown = int.MaxValue
        }

        public int NumberOfDays {
            get {
                if (ViewState["NumberOfDays"] == null) {
                    return 4;
                } else {
                    return (int)ViewState["NumberOfDays"];
                }
            }
            set {
                if (value < 1 || value > 10) {
                    ViewState["NumberOfDays"] = 4;
                } else {
                    ViewState["NumberOfDays"] = value;
                }
            }
        }


        protected override void Render(HtmlTextWriter writer) {
            Random rand = new Random();

            for (int i = 0; i < this.NumberOfDays; i++) {
                int weatherValue = rand.Next(0, 3);
                WeatherType todaysWeather = (WeatherType)weatherValue;

                Image img = new Image();
                img.ImageUrl = string.Format("~/images/{0}.gif", todaysWeather.ToString());
                img.AlternateText = todaysWeather.ToString();

                writer.AddStyleAttribute(HtmlTextWriterStyle.TextAlign, "center");
                writer.RenderBeginTag(HtmlTextWriterTag.Div);
                img.RenderControl(writer);
                writer.WriteBreak();
                writer.Write(todaysWeather.ToString());
                writer.RenderEndTag();
            }

        }
    }
}
0
 

Author Comment

by:purplesoup
ID: 21792799
ok - this seems to be the difference. When I run the example it works but the code is basically the same as my code.

The difference I think is the VSS format version. The example solution file has this:

Microsoft Visual Studio Solution File, Format Version 9.00

The file I am running has this:

Microsoft Visual Studio Solution File, Format Version 10.00

If I put the example code into a new solution I get the error.

If anyone has any suggestions on moving on from here I will look at them, otherwise I will say this is the "solution".
0
 

Author Closing Comment

by:purplesoup
ID: 31465681
Thanks for your efforts in trying to help.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now