473,387 Members | 1,882 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,387 software developers and data experts.

How to know the base class of a control?

I wanna check if a control is inherited from an specific class, how do
I do this?

Example: I wanna check if a control is inherited from ContainerControl
class.

Aug 4 '06 #1
4 1233
osmarjunior wrote:
I wanna check if a control is inherited from an specific class, how do
I do this?

Example: I wanna check if a control is inherited from ContainerControl
class.
Try:

if(myControl is ContainerControl)
Aug 4 '06 #2
if (ctrl.GetType().IsSubclassOf(typeof(ContainerContr ol)))
System.Diagnostics.Debug.WriteLine("Inherits ContainerControl");
else
System.Diagnostics.Debug.WriteLine("Doesn't inherit ContainerControl");
/claes

"osmarjunior" <os*********@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
>I wanna check if a control is inherited from an specific class, how do
I do this?

Example: I wanna check if a control is inherited from ContainerControl
class.

Aug 4 '06 #3
Just use :
if(control is ContainerControl) {
// do something
}
or:
ContainerControl cont = control as ContainerControl;
if(cont!=null) {
// do something
}

Marc
Aug 4 '06 #4
"osmarjunior" <os*********@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
I wanna check if a control is inherited from an specific class, how do
I do this?

Example: I wanna check if a control is inherited from ContainerControl
class.
//Note: untested

Label controlToCheck = new Label();

ContainerControl possibleContainer = controlToCheck as ContainerControl;
if(possibleContainer != null)
{
//Perform Magic Here
}
Aug 4 '06 #5

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

Similar topics

8
by: TS | last post by:
I am trying to get set a property of a control on the inherited class from base class. I imagine i have to use reflection, so could someone give me the code to do it? something like this?...
3
by: John B | last post by:
I have a variable in a base class defined as: protected Control validationControl; How can I ensure that it is set is any dervied classes. I see that you cannot set variables to abstract. ...
6
by: Robert Werner | last post by:
I want to write one general purpose set of code that will handle the population (where required) of all controls on a form. Though I'm new to C# my instinct is to somehow hook into the Load event...
3
by: Mikip | last post by:
Hi, I have some properties that are common to all pages so I have created a base class which every page inherits from. I now also want to use these properties within User Controls on the page....
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: balystyk | last post by:
Are there any possible issues with creating a base class (adding common properties) for a user control using a class file and not a user control (.ascx and code-behind) in asp.net 2.0? I have...
5
by: EqDev | last post by:
I have a class that is a control derived from UserControl. I want to use serialization and deserialization with this calss but I get an exception "Cannot serialize member...
26
by: nyathancha | last post by:
Hi, How Do I create an instance of a derived class from an instance of a base class, essentially wrapping up an existing base class with some additional functionality. The reason I need this is...
0
by: Steve Richter | last post by:
my composite control does not render correctly the 2nd time it is made visible. When I change the base class from CompositeControl to WebControl, the control works as it should. public class...
3
by: =?Utf-8?B?c29uaWNt?= | last post by:
Hi, What is the best way of populating a repeater control from a SQL Database using a base class. I am trying to impliment a base class that can be used across future websites and will populate...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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:
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.