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,861 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

696 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