?
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
Medium Priority
?
1,892 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 1000 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

Industry Leaders: 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!

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

765 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