473,591 Members | 2,810 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(Obj ect sender, EventArgs e)
{
if(ListRepeater .DataSource == null
{
ListRepeater.Vi sible = 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(Obj ect sender, EventArgs e)
{
if(GetRepeater( ).DataSource == null
{
GetRepeater().V isible = 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 1444
Anyone have any suggestions about this?

thanks,

Eric

"Eric Theil" <er**@nospam.co mwrote in message
news:eT******** ******@TK2MSFTN GP03.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(Obj ect sender, EventArgs e)
{
if(ListRepeater .DataSource == null
{
ListRepeater.Vi sible = 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(Obj ect sender, EventArgs e)
{
if(GetRepeater( ).DataSource == null
{
GetRepeater().V isible = 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
1787
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 straightforward and dare I say intuitive? (well, as intuitive as you can get w/ MFC.) Anyhow, I am wanting to create some controls of my own w/ C#. I'm not quite sure where to start though. I created a Windows Control library project, and I get a...
2
2083
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 base all my custom controls on this new MyUserControl Class. Is this the way to go? The MyUserControl would not actually have any UI component and should be abstract I think. Does this mena that I should not create the control by just selecting...
1
13663
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 and set methods on the user control "editButton.ascx" which work fine. How do i pass parameter into the user controls "c1", "c2" ? Here is a bit of my code that is calling the user control from the
8
1591
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 customContentControl = CType(Page.LoadControl("mycontrol.ascx"),UserControl)panel_controlHolder.Con trols.Add(customContentControl) ===================================================
1
1077
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 ForeColor property that I leave exposed in my inherited class. My intent here is to allow users to set this property and then use it as the color for several controls that I dynamically place onto the base Usercontrol as needed. I am placing...
2
5051
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 the VS2005 designer, but at runtime, the controls are in different locations and different sizes. I have been able to restore their sizes by putting a hack together that will set their sizes to the correct values in the UserControl's Resize...
5
1807
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 the following from Steven Cheng, but am having a hard time following: In ASP.NET 2.0, the pages and usercontrols and their codebehind classes are dynamically compiled at runtime. However, the dynamic compilation is possible to compile the page or...
8
3168
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 I'm having is that the partial class signature in my projectDetails.ascx.cs file looks like this: public partial class ProjectDetailsControl<TEntryServiceProvider: UserControl, INamingContainer where TEntryServiceProvider : IEntryServiceProvider...
2
1434
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 the virtual method. I have a page on which I placed these usercontrols together. The base usercontrol's datagrid gets populated fine however in the override method of the child usercontrol it is throwing an exception when I am trying to bind the...
0
8362
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7992
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8225
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5732
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5400
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3891
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1465
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1199
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.