Results 1 to 6 of 6

Thread: ASP.NET Custom Control Library! =/

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    100

    ASP.NET Custom Control Library! =/

    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
    Last edited by toto; Aug 22nd, 2003 at 03:15 PM.

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    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.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    100
    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:

    Code:
    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>");
    			}
    		}
    	}
    }

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    100
    This next class is the main collection which I'm trying to be able to modify using the designer once the library is compiled:

    Code:
    	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

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    100
    And finally the tab class:

    Code:
    	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;
    		}
    	}

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    100
    The error lies within this code:

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width