I developed my first Web Custom Control, but I'm getting a frustration error at runtime. The control itself compiles fine. I added it to my controls in the IDE, it drags and drops fine, its properties are visible in the Properties window, etc. Everything seems fine, but when I start a debugging session, I get this error:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0234: The type or namespace name 'CompositeControl' does not exist in the class or namespace 'CompositeControl.CompositeControl' (are you missing an assembly reference?)
Source Error:
Line 79:
Line 80: private System.Web.UI.Control __BuildControlcomCntrl() {
Line 81: CompositeControl.CompositeControl __ctrl;
Line 82:
Line 83: #line 14 "http://localhost/CompositeControlTest/WebForm1.aspx"
Source File: c:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\compositecontroltest\bd24d331\53d60527\bl5lmgnt.0.cs Line: 81
Here's my control's code:
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace CompositeControl
{
/// <summary>
/// Summary description for CompositeControl.
/// </summary>
public class CompositeControl : Control, INamingContainer
{
public CompositeControl()
{
ViewState["MinValue"] = 0;
ViewState["MaxValue"] = 1000;
}
protected override void CreateChildControls()
{
Label lbl = new Label();
Button btn = new Button();
lbl.Height = Unit.Pixel(25);
lbl.Width = Unit.Pixel(75);
lbl.Text = "0";
btn.Height = Unit.Pixel(25);
btn.Width = Unit.Pixel(75);
btn.Text = "Go";
Controls.Add(lbl);
Controls.Add(btn);
btn.Click += new EventHandler(btnClick);
}
[Category("Behavior"), Description("Minimum value")]
public int MinValue
{
get
{
return Convert.ToInt32( ViewState["MinValue"] );
}
set
{
ViewState["MinValue"] = value;
}
}
[Category("Behavior"), Description("Maximum value")]
public int MaxValue
{
get
{
return Convert.ToInt32( ViewState["MaxValue"] );
}
set
{
ViewState["MaxValue"] = value;
}
}
public void btnClick( Object sender, System.EventArgs e )
{
System.Random r = new System.Random();
int intValue;
intValue = r.Next( Convert.ToInt32( ViewState["MinValue"]), Convert.ToInt32( ViewState["MaxValue"]) );
Label lbl = (Label) Controls[0];
this.EnsureChildControls();
lbl.Text = intValue.ToString();
}
}
}
What could be going wrong?