newbie question on Custom Controls in C#

Discussion in 'ASP .Net Building Controls' started by John Richardson, Feb 23, 2006.

  1. 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
     
    John Richardson, Feb 23, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Axel Dahmen
    Replies:
    1
    Views:
    518
    Teemu Keiski
    Nov 12, 2003
  2. user
    Replies:
    1
    Views:
    441
    Kevin Spencer
    Jul 19, 2007
  3. rodchar
    Replies:
    0
    Views:
    399
    rodchar
    Nov 26, 2007
  4. DaBrain

    Two question about ASP.NET Custom Controls [Newbie]

    DaBrain, Oct 28, 2006, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    124
    Michael Hamrah
    Oct 29, 2006
  5. anon
    Replies:
    0
    Views:
    215
Loading...

Share This Page