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,837 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 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

20 Experts available now in Live!

Get 1:1 Help Now