PDA

Click to See Complete Forum and Search --> : ASP.NET Custom Control Library! =/


toto
Aug 22nd, 2003, 01:04 PM
I've been trying forever to get my own custom control library to work(it's for asp.net).

I finally got far enough where the collection property of my control actually works!! (in the designer). Now when I try to run the control I get the following error:

Cannot create an object of type 'dbw.dbwTabCollection' from its
string representation '(Collection)' for the 'Tabs' property.

Could someone please help!

Thanks in advance,
Mitchel

hellswraith
Aug 22nd, 2003, 02:32 PM
As with any question about errors, we need to see the code to help you. We can't just whip up the correct code without knowing what you are doing exactly. Post your code and we will help.

toto
Aug 22nd, 2003, 03:01 PM
Agreed, sorry about that..it's a bit of code..let me explain it first.

I created a new "ASP.NET Custom Control Library" and under the main class I have the following:


namespace dbw
{
[DefaultProperty("Text"),
ToolboxData("<{0}:TabControl runat=server></{0}:TabControl>")]
public class TabControl : WebControl //System.Web.UI.WebControls.WebControl
{
private dbwTabCollection tabs = new dbwTabCollection();

[Bindable(true)]
[Category("Design")]
public dbwTabCollection Tabs
{
get
{
return tabs;
}
set
{
if (value != null)
tabs = value;
}
}

protected override void Render(HtmlTextWriter output)
{
for (int i = 0; i < tabs.Count; i++)
{
dbwTab tmp = (dbwTab) tabs[i];
output.Write(tmp.Text + "<hr>");
}
}
}
}

toto
Aug 22nd, 2003, 03:03 PM
This next class is the main collection which I'm trying to be able to modify using the designer once the library is compiled:


public class dbwTabCollection : CollectionBase
{
public dbwTab Add(dbwTab value)
{
List.Add(value as object);
return value as dbwTab;
}

public void AddRange(dbwTab[] tabs)
{
foreach(dbwTab tab in tabs)
Add(tab);
}

public void Remove(dbwTab value)
{
base.List.Remove(value as object);
}

public void Insert(int index, dbwTab value)
{
// Use base class to process actual collection operation
base.List.Insert(index, value as object);
}


public void Remove(int Index)
{
if (Index > Count - 1 || Index < 0)
{
//System.Windows.Forms.MessageBox.Show("Index not valid!");
}
else
{
List.RemoveAt(Index);
}
}

public override string ToString()
{
dbwTab tmp = new dbwTab();
return tmp.ToString();
}

public bool Contains(dbwTab value)
{
// Value comparison
foreach(dbwTab t in base.List)
if (value.Equals(t))
return true;

return false;
}


public dbwTab this[int index]
{
// Use base class to process actual collection operation
get { return (base.List[index] as dbwTab); }
set { base.List[index] = value; }
}

public int IndexOf(dbwTab value)
{
// Find the 0 based index of the requested entry
return base.List.IndexOf(value);
}
}


p.s. I'm sure this class will be interesting to many people developing their own controls so here are a few meta words:
collection, collections, webcontrol, custom, property, designer

toto
Aug 22nd, 2003, 03:05 PM
And finally the tab class:


public class dbwTab
{
private string text;

public dbwTab()
{
text = "tab";
}

public string Text
{
get {return text; }
set {text = value; }
}


public override string ToString()
{
return text;
}
}

toto
Aug 22nd, 2003, 03:07 PM
The error lies within this code:

<cc1:tabcontrol id=TabControl3
style="Z-INDEX: 104; LEFT: 192px; POSITION: absolute; TOP: 200px" runat="server" Height="128px" Width="336px"
Tabs="(Collection)" BackColor="Red"></cc1:tabcontrol>

The designer tries to use the library which is already compiled. It works fine when it's just in the ide mode, but as soon as I try to run the asp.net webform the error described in my first post occurs.

Hopefully someone can help me with this.

Thanks guys,
Mitchel