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
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