Archived

This topic is now archived and is closed to further replies.

mirirom

Understanding .NET custom web controls

Recommended Posts

heya, i've posted this question on other sites but since the useful advice i've ever recieved has been here, i figured i'd give it a shot. i'm taking my first stab at implementing custom controls in a ASP.NET 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...
               {documentType:abstract}
                          ||
            ______________||____________
           |                            |
 {transmittalTypeublic}   {meetingLogTypeublic}
           
and the documentType inherits for System.Web.UI.WebControls.WebControl. 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
<@ TagPrefix="dt" Namespace="AppFoo.codeBin" Assembly="AppFoo">
...
<:someInstance id="bar" runat="server" />   
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...
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 ("Error Building Control: instanceName") 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 ::.. [edited by - mirirom on October 6, 2003 5:16:18 PM] [edited by - mirirom on October 6, 2003 5:17:44 PM]

Share this post


Link to post
Share on other sites
for those that are interested, i found the fix. my problem was syntactical (and my post above is also missing the custom tagPrefix as well).

the compiled class name MUST be used after the custom tag. so, for example...

<dt:someInstance id="foo" runat="server" />

should read as

<dt:nameOfClass id="foo" runat="server" />

and there you have it....

Share this post


Link to post
Share on other sites
Edit: beat me to it.

You need to add an entry to the AssemblyInfo file in the custom control project that looks like...


<Assembly: TagPrefix("AppFoo.codeBin", "dt")>


and then declare the instance in the page like...


<dt:transmittalType id="bar" runat="server" />


cheers,
Paul Cunningham

Edit: added code tags
Edit: added source tags

[edited by - PaulCunningham on October 7, 2003 12:41:30 PM]

Share this post


Link to post
Share on other sites