Declaring controls in base usercontrol

E

Eric Theil

Hello,

I'm just getting into ASP.Net 2.0 and I can't figure out an effective way
(or at least one that I think is effective) to perform one of the techniques
I used to use in 1.0/1. As an example, I have multiple user controls whose
code behind functionality is identical, but display is completely different,
so I would create a base usercontrol (inheriting from UserControl), and
declare a protected repeater. I would then make sure a repeater with that Id
appeared in the .aspx page of each UserControl which inherited from this
base. As an example

// Base List
public ListBase : UserControl
{
protected Repeater ListRepeater;

protected override OnPreRender(Object sender, EventArgs e)
{
if(ListRepeater.DataSource == null
{
ListRepeater.Visible = false;
}
}

other functionality...
}

// User control inheriting from ListBase, with a Repeater declared on the
..aspx page with an Id of ListRepeater
public UserList : ListBase{}

But in 2.0, I get a message that the controls I decalre in the ListBase
class are hiding controls declared in the base. I understand why this
message appears when compiling, so, I implemented a Template pattern like
this:

public ListBase : UserControl
{
// The functionality should be overriden in a subclass
protected virtual void GetRepeater(){ return new Repeater(); }

protected override OnPreRender(Object sender, EventArgs e)
{
if(GetRepeater().DataSource == null
{
GetRepeater().Visible = false;
}
}
}

// User control inheriting from ListBase, with a Repeater declared on the
..aspx page with an Id of ListRepeater
public UserList : ListBase
{
override protected GetRepeater()
{
return ListRepeater;
}
}

Something doesn't feel right here and I'm wondering if anyone else has any
suggestions on a better implementation. Heck, I would even appreciate some
reinforcement if this is an effective means.

Thanks,

Eric
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top