newbie question on Custom Controls in C#

J

John Richardson

I have just started working on an ASP.Net 1.0 project as my first forray
into ASP.Net (or ASP for that matter), and have a general question about
Custom Controls. This is probably painfully newbian, so bear with me.

In my project, on a page, I will be processing some groups of data. I made
a custom control, call it CUSTOM_A that can display each group: it's very
simple, just a heading label, and a literal for the content.

In a for-loop on the CodeBehind, I want to dynamically instantiate and load
a collection of these custom controls, loading the data in each one.

The following are my questions about this:

1) The designer declares the custom control as a static class. Why is this
important? Is it normal/good practice, then, when dynamically building a
collection of these objects, to have to make a second class, non-static
(call it CUSTOM_B) and inherit from the static one, CUSTOM_A?

2) When I did the above, I was dismayed to find that when I instantiated the
object like so:
Custom_B custom = new Custom_B()
that none of the child controls (my literal and label) were created in
memory, and I got a null-reference error. Basically, the Page_Load event
doesn't fire when you instantiate the object.

If you know of a good tutorial explaining what I am trying to do here, that
would be great. ASP.Net is obviously very different from the stand alone
variety of programming.

Any help would be appreciated. I want to leverage the code encapsulation
abilities of custom controls.

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top