Click to See Complete Forum and Search --> : "Inherits" problem with User Control


jedi58
09-26-2007, 06:48 AM
I've got a very strangle problem when dealing with dynamic UserControls in C#.net.

I'm using the LoadControl function to load a number of controls and add them to a placeholder on a page. However I've started getting a very strange problem with them. For example I could have made no changes to a particular User Control and then on one refresh I'll suddenly start getting:


Compiler Error Message: ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).


The ASCX file has the following at the top:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="widget2.ascx.cs" Inherits="ContentWidget" %>

and the code behind file contains a class that has the following definition:

public partial class ContentWidget : System.Web.UI.UserControl

If I make any change to it then it's almost certain that "Inherit" error will start occurring, even if I just try a variable assignment inside the Page_Load function. The same thing happens if I try and change the name of the class and inherits to something else too. Once I've got the error it usually happens for a few refreshes and then just disappears.

Does anyone have any thoughts what might be the cause of this?



widget2.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="widget2.ascx.cs" Inherits="ContentWidget" %>

<asp:Image ID="imageControl" ImageUrl="" runat="server" />

widget2.ascx.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;


public partial class ContentWidget : System.Web.UI.UserControl
{
public int widgetID;

protected void Page_Load (object sender, EventArgs e)

{
}
}