User Controls and Inheritance

H

headware

I have a user control that is basically a Datagrid with a few
additional controls for filtering the data and showing/hiding columns.
I'd like to be able to reuse this control in different places
throughout my code but allow it to work with different tables in the
database.

I thought that I would use the Template pattern to achieve this. I put
all the functions in an abstract base class which inherited from
UserControl except a BindDataGrid() function which I left for the
derived classes to override depending on the table they want to
display in the datagrid. Everything compiled fine but I can't get the
thing to run. The InitialComponent() function keeps erroring out when
it tries to attach the event functions in the base class because the
controls are null.

I must admit that I don't understand how those variables are set in
normal ASPX pages but it must be in the code that is generated behind
the scenes.

I also don't understand how the .aspx pages should be related. When I
actually want to create another control that inherits from the base
user control, obviously the code behind of the derived control will
inherit from the codebehind of the base control, but what about the
..aspx page itself? Do I leave it blank and make it inherit from the
base control's .aspx page? I'm kinda foggy on that.

It looks like some people have tried this before but I haven't seen
anyone definitively say that this does or doesn't work. I think could
probably achieve the effect I'm looking for using the Strategy pattern
instead of the Template pattern, but I'm just curious as to why this
isn't working.

Thanks,
Dave
 

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,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top