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,875 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
Independent Software Vendors: 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

728 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