Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Building Composite Controls with the toolbox

Reply
Thread Tools

Building Composite Controls with the toolbox

 
 
None
Guest
Posts: n/a
 
      02-03-2006

I'm building my first ASP.NET 2.0 app. I'm familiar with 1.0 and 1.1 and
have read various books, so I'm not a complete beginner. However, I've
become stumped on something that I feel should be easy, but is causing me
some confusion. I've searched on the net, but can't find a resolution.

I'm trying to build a server control that inherits from CompositeControl,
I would like it to be visible in the toolbox.

Here is exactly what I'm doing.

1. Create a new "ASP.NET 2.0 Web Site" (c#)
2. Add another new project (c#\windows\web control library)
3. Open the class "WebCustomControl1.cs"
4. Modify the class (notice I've changed the base blass):

----------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebControlLibrary1
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:WebCustomControl1 runat=server></
{0}:WebCustomControl1>")]
public class WebCustomControl1 : CompositeControl
{
protected TextBox tb = new TextBox();

[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
public string Text
{
get
{
return tb.Text;
}

set
{
tb.Text = value;
}
}

protected override void CreateChildControls()
{
base.Controls.Add(tb);
base.CreateChildControls();
}

}
}
------------------
5. Compile the solution

6. In the web site project add a reference to the web control library
project (This adds a bin folder to my website with the DLL inside)

7. One problem, there's no item in the toolbox when opening a web page
like default.aspx.

8. If I add a new Web custom control to the web control library project
and recompile, then open default.aspx. the new control
(webcustomcontrol2) is in the toolbox.

9. I can drag it on the form I get the HTML
<cc1:WebCustomControl2 ID="WebCustomControl2_1" runat="server" />
I can rename it to:
<cc1:WebCustomControl1 ID="WebCustomControl2_1" runat="server" />
This displays the text box from my CompositeControl and it works fine.



Why can't I see the composite control in the toolbox?

One strange thing I found, If I right click on the webcontrol project and
select "Remove" then add it in again. Both controls are visible in the
toolbox. However is I exit visual studio and restart it's gone again.

I don't any problems with the second control (based on WebControl) only
the first control (based on CompositeControl)

Do I need more code in the Composite control? I feel I may be missing
something obvious.

Please please help.

Thanks,
Craig

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Example of Building Composite Controls in ASP.NET 2.0 Sasha ASP .Net Building Controls 0 05-31-2006 06:44 PM
Composite vs non composite Controls Mike ASP .Net Web Controls 4 03-11-2005 05:47 AM
Possible to create a composite control that has a child control that is a validator that validates the composite control itself? Jonathan Eric Miller ASP .Net Building Controls 2 07-22-2004 10:58 PM
Composite control with dynamic composite controls sleigh ASP .Net 1 02-12-2004 06:24 PM
Question on building composite controls Emjay ASP .Net Building Controls 0 12-03-2003 02:05 AM



Advertisments