473,395 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Declaring controls in base usercontrol

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
Oct 20 '06 #1
1 1437
Anyone have any suggestions about this?

thanks,

Eric

"Eric Theil" <er**@nospam.comwrote in message
news:eT**************@TK2MSFTNGP03.phx.gbl...
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

Oct 23 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jim | last post by:
I'm a little new to the C# way of doing thisgs... Although I've done this sort of thing before in VS 6 / MFC... creatnig controls, ActiveX controls, etc. Creating controls in MFC is pretty...
2
by: John B | last post by:
Hello I want to create a set of controls that have some common methods and properties. I was thinking that I should subclass the UserControl class and add these common features there and then...
1
by: Josh | last post by:
Hi Guys, I have been having a big problem with trying to pass parameters into a user control when the user control is dynamically loaded into a placholder. I am developing in c#. I have get...
8
by: darrel | last post by:
This is a follow-up to a question I asked yesterday. I'm loading a UC programatically as such: =================================================== public customContentControl as UserControl...
1
by: Ray Cassick \(Home\) | last post by:
Ok, here is apparently another odd one... I am (as I said in a previous posting here) building a user control that inherits from System.Windows.Forms.UserControl. This base class contains a...
2
by: Steve | last post by:
This is a weird one. I have a series of "SmartParts" which are CAB (Composite Application Block) Views which are finally just UserControls (99% of the time) Anyway, I layout my UserControl in...
5
by: sck10 | last post by:
Hello, I am trying to add the following to a App_Code class. The error I am getting references "Page.Controls". I would like to call this from my content page which uses MasterPages I read...
8
by: mark.norgate | last post by:
I've run into a few problems trying to use generics for user controls (classes derived from UserControl). I'm using the Web Application model rather than the Web Site model. The first problem...
2
by: =?Utf-8?B?RGlmZmlkZW50?= | last post by:
Hello All, I have a base usercontrol which has a datagrid and a virtual method to populate the datagrid. I developed a child usercontrol which inherits the base usercontrol and also overrides...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.