Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Understanding custom controls 1

Status
Not open for further replies.

mirirom

Programmer
Jul 21, 2001
110
US
heya,

i'm taking my first stab at implementing custom controls in a web app and i keep getting errors (surprise surprise) while trying to build instances of custom controls. first off, these are not User Controls, rather, i'm creating a class heirarchy starting with an abstract prototype and instantiating derived child instances.

for example, here's a sample implementation...
Code:
               {documentType:abstract}
                          ||
            ______________||____________
           |                            |
 {transmittalType:public}   {meetingLogType:public}

as far as i know, all i need to do is add a directive to the top of the aspx doc and an accompanying tag to the doc as well. like
Code:
<%@ TagPrefix=&quot;dt&quot; Namespace=&quot;AppFoo.codeBin&quot; Assembly=&quot;AppFoo&quot;%>
...
<dt:someInstance id=&quot;bar&quot; runat=&quot;server&quot; />

in my class code (which inherits from System.Web.UI.WebControls.WebControl), i'm defining a few protected fields for various UI widgets (labels, textbxs, etc). instances of these members are created within a custom InitializeComponent call via the constructor and then added to a local arrayList. lastly..., the CreateChildControls method (which i believe is called during the actual building) adds the elements of the arrayList to the objects Controls collection, e.g...
Code:
this.Controls.Clear();
foreach(WebControl wc in arlLocalCtls)
{this.Controls.Add(wc);}

unfortunately, i can't seem to get a single instance of any custom control to be built. design-time shows an immediate error (&quot;Error Building Control: instanceName&quot;) in HTML view, and errors are simply returned in the browser on execute.

am i missing a key step here or the concept as a whole or...? any help/advice is greatly appreciated. thanks!

mirirom
 
Hi,

Is the name of your class containing the code for your custom control &quot;someInstance&quot;? Try changing the name of your control in your page-level declaration to the name of your class. For example, if your wrote a &quot;StockTicker&quot; class, It should be:

<dt:StockTicker id=&quot;foo&quot; runat=&quot;server&quot;/>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top