Hi There,
I have a usercontrol that presents the majority of a page's content. Within
the ASP.NET application it appears as XXXX.PageContro l, where XXXX is the
namespace of my project. There will only ever be one and onely one of these
controls per page. I want to identify the control and set a particular
property depending upon what the current page is.
I want to find this control generically, so I wrote the following code:
for each ctl as control in me.controls
if ctl.GetType is GetType(PageCon trol) Then
....
exit for
end if
next
But this is never true. If I examine what is returned by
ctl.GetType.ToS tring, I see "ASP.PageContro l_ascx".
Any advice on how to get this comparison working would be appreciated!
Cheers,
Trevor 2 1868
That is because ASP.NET actually inherits from the class that you create
(that is what appears on your page, not what you create). You will have to
check for the type that is actually created when the code is compiled.
You might try using something like the "is" operator. I believe this takes
into account inheritance, so "if( ctl is typeof(PageCont rol)" this might
return true of any class that derives from PageControl.
"Trevor Andrew" <nntp_No_S.p.a. m.@tassoc.com.a u> wrote in message
news:54******** *************** ***********@mic rosoft.com... Hi There,
I have a usercontrol that presents the majority of a page's content.
Within the ASP.NET application it appears as XXXX.PageContro l, where XXXX is the namespace of my project. There will only ever be one and onely one of
these controls per page. I want to identify the control and set a particular property depending upon what the current page is.
I want to find this control generically, so I wrote the following code:
for each ctl as control in me.controls if ctl.GetType is GetType(PageCon trol) Then .... exit for end if next
But this is never true. If I examine what is returned by ctl.GetType.ToS tring, I see "ASP.PageContro l_ascx".
Any advice on how to get this comparison working would be appreciated!
Cheers, Trevor
Hi Peter,
Thanks for your reply. Your suggestion worked. The expression "Typeof (ctl)
is PageControl" returned true when expected.
Regards,
Trevor Andrew
"Peter Rilling" wrote: That is because ASP.NET actually inherits from the class that you create (that is what appears on your page, not what you create). You will have to check for the type that is actually created when the code is compiled.
You might try using something like the "is" operator. I believe this takes into account inheritance, so "if( ctl is typeof(PageCont rol)" this might return true of any class that derives from PageControl.
"Trevor Andrew" <nntp_No_S.p.a. m.@tassoc.com.a u> wrote in message news:54******** *************** ***********@mic rosoft.com... Hi There,
I have a usercontrol that presents the majority of a page's content. Within the ASP.NET application it appears as XXXX.PageContro l, where XXXX is the namespace of my project. There will only ever be one and onely one of these controls per page. I want to identify the control and set a particular property depending upon what the current page is.
I want to find this control generically, so I wrote the following code:
for each ctl as control in me.controls if ctl.GetType is GetType(PageCon trol) Then .... exit for end if next
But this is never true. If I examine what is returned by ctl.GetType.ToS tring, I see "ASP.PageContro l_ascx".
Any advice on how to get this comparison working would be appreciated!
Cheers, Trevor This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Leszek Taratuta |
last post by:
Hello,
I have the following code:
// Load the MenuBar.ascx user control. The control defines SavePropertyEvent
event.
UserControl ctrl =
(UserControl)Page.LoadControl("~/MyApp/Controls/MenuBar.ascx");
// Get type information of the loaded user control.
|
by: oliver |
last post by:
QUESTION: How to access an object embedded in a UserControl through
Javascript file?
Another way to ask this question: How to execute script from a UserControl,
accessing other objects in that UserControl? (Script attached to, and
executed by, a UserControl embedded server control can ‘see’ the UserControl
through the root document architecture. How to get the script to execute and
‘see’ other server controls in the...
|
by: daniel.hedz |
last post by:
I am generating a usercontrol dynamically successfully, but when I try
to find that usercontrol I get a type mismatch. This is what I am
doing:
//Loading my usercontrol
MyWebApp.Folder.Folder.MyUsercontrol myUC =
(MyWebApp.Folder.Folder.MyUsercontrol)
LoadControl("~/Folder/Folder/MyUsercontrol.ascx");
|
by: acadam |
last post by:
In my application I have a usercontrol called "base" with a panel
called "pnl1"; in "pnl1" I put my usercontrol.
Now I would like to have 2 possibilities: from "base" to load another
control called "ctl2" (and there's no problem) but I would like also
to load "ctl2" from "ctl1"!
The name of the control to load is "stored" into Session("activeCtl")
base.ascx Page_Load code:
Dim ctl As UserControl = New UserControl
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
|
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,...
|
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...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |