473,397 Members | 2,099 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,397 software developers and data experts.

Custom controls derived from common usercontrol ancestor

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 New UserControl as this generates the UI code automatically?

Each custom control will contain either a textbox or combobox. Can I write
the MyUserControl class in such a way as to assume this and access a
property (eg. enabled) somwhow or do I need to implement this in each custom
class seperately?

I have not really done this before, so any help would be appreciated.

Thanks

John

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 16 '05 #1
2 2068
From what you have stated the approach you suggest is the correct approach.

You should never create an instance of your base user control as it will not
be of any use as it will not have an visual components.

If all the derived user controls have the same functionality then yes this
can be placed in the base user control.

--
HTH

Ollie Riches
http://www.phoneanalyser.net

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a programmer
helping programmers.

"John B" <sp******@hotmail.con> wrote in message
news:42**********@127.0.0.1...
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 New UserControl as this generates the UI code automatically?
Each custom control will contain either a textbox or combobox. Can I write
the MyUserControl class in such a way as to assume this and access a
property (eg. enabled) somwhow or do I need to implement this in each custom class seperately?

I have not really done this before, so any help would be appreciated.

Thanks

John

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption

=----
Nov 16 '05 #2
Hi,

First of all, will your control have more than the textbox/combobox?
If yes then extending UserControl is the way to go, otherwise you should
explore other ways as declaring an interface and extending TextBox/ComboBox

Response to your questions are inline
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?
Yes, depending of the answer to the above question
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 New UserControl as this generates the UI code
automatically?
You should declare it as abstract as you will never create an instance of
it.
Each custom control will contain either a textbox or combobox. Can I write
the MyUserControl class in such a way as to assume this and access a
property (eg. enabled) somwhow or do I need to implement this in each
custom
class seperately?


you could do several things, you could define an enum to indicate what
control to create and pass it ot the constructor, in this way you can assure
that you create only one type of control. How to access it depends also of
your preferences, you could declare a :
public Control GetControl
property to get the current control
or you could create two properties, each one return either null or the
control currently in use

public TextBox GetTextBox
public Combobox GetCombo

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


Nov 16 '05 #3

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

Similar topics

7
by: Martin Schulze | last post by:
Hello, i tried to compose myself a custom usercontrol which is derieved from System.Windows.Forms.UserControl. It contains 2 comboboxes and one textbox (which are also custom controls, but...
2
by: Pham Nguyen | last post by:
Has anyone seen an example of a textbox server control that has built-in client-side validation? I'd like to build a server control that extends the System.Web.UI.WebControls.TextBox class to allow...
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...
6
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to...
4
by: =?Utf-8?B?cmtvemxpbg==?= | last post by:
Is it possible to remotely host custom types? Some background... We have an application that uses custom user controls as 'templates' for entering certain kinds of data. The application is...
1
by: rajendra | last post by:
hi i am rajendra i am posting my first question to this group i have doubt from last few days .i want to clear it why we need user control and wher should we use it,and the execution of the...
10
by: Cirene | last post by:
I know that sometimes referring to controls deep in a page using a Master Page can be funky. For a website using a standard header/footer/nav, do you prefer using User Controls for the common...
4
by: =?Utf-8?B?UmljaEI=?= | last post by:
I am trying to create a project using the ASP.NET AJAX accordion control. I would like to dynamically add panes to the control with a form template added when the pane is added. I have tried...
4
by: Stewart Berman | last post by:
I have a compound custom control derived from UserControl. It has three controls on it -- two custom controls and a Label control. When the control is added to a from and then resized using the...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.