This is a follow-up to a question I asked yesterday.
I'm loading a UC programatically as such:
=============== =============== =============== ======
public customContentCo ntrol as UserControl
customContentCo ntrol =
CType(Page.Load Control("mycont rol.ascx"),User Control)panel_c ontrolHolder.Co n
trols.Add(custo mContentControl )
=============== =============== =============== ======
This works fine, but got hung up on how to now pass a property or variable
value to this loaded control.
It was suggested to use a base class or an interface. I've done a bit with
interfaces, but wanted to try understanding how the base class option would
be imnplemented.
What I eventually would like to be able to do is pass a value like this:
=============== =============== =============== ======
customContentCo ntrol.property = 'whatever'
=============== =============== =============== ======
Now, from what I understand, my problem is that I'm casting the loaded UC as
a 'UserControl' instead of a base-class derived from the UserControl class.
Am I on the right path with that logic? If so, what does the base-class
definition do. Is it merely creating a namespace so I can access it? 8 1592
This is the other way round.
When you create a user control, you are creating a class that inherits from
UserControl (ie. UserControl is your control base class).
As when you load your control, you use a UserControl variable, you are only
able to access to what UserControl does (and your control is able to perform
all this as it inherits these capabilities from the UserControl (base)
class).
If you load your control using a MyControl variable, you'll be able to
access all the capabilites included those you added (change also the CType).
Patrice
--
"darrel" <no*****@hotmai l.com> a écrit dans le message de
news:ut******** *****@tk2msftng p13.phx.gbl... This is a follow-up to a question I asked yesterday.
I'm loading a UC programatically as such:
=============== =============== =============== ====== public customContentCo ntrol as UserControl customContentCo ntrol =
CType(Page.Load Control("mycont rol.ascx"),User Control)panel_c ontrolHolder.Co n trols.Add(custo mContentControl ) =============== =============== =============== ======
This works fine, but got hung up on how to now pass a property or variable value to this loaded control.
It was suggested to use a base class or an interface. I've done a bit with interfaces, but wanted to try understanding how the base class option
would be imnplemented.
What I eventually would like to be able to do is pass a value like this:
=============== =============== =============== ====== customContentCo ntrol.property = 'whatever' =============== =============== =============== ======
Now, from what I understand, my problem is that I'm casting the loaded UC
as a 'UserControl' instead of a base-class derived from the UserControl
class. Am I on the right path with that logic? If so, what does the base-class definition do. Is it merely creating a namespace so I can access it?
> If you load your control using a MyControl variable, you'll be able to access all the capabilites included those you added (change also the
CType).
Your explanation helps. Thanks! I'm still not quite sure *what* I need to
change the CType to, though. Is it the class of the UC I am loading?
-Darrel
Hello darrel,
I posted an example of how to accomplish what you need in my answer to your
previous post. Did you have additional questions?
--
Matt Berther http://www.mattberther.com If you load your control using a MyControl variable, you'll be able to access all the capabilites included those you added (change also the CType).
Your explanation helps. Thanks! I'm still not quite sure *what* I need to change the CType to, though. Is it the class of the UC I am loading?
-Darrel
> I posted an example of how to accomplish what you need in my answer to
your previous post. Did you have additional questions?
I'm taking a second look at your example. It's in C#, so it's a bit foreign
to me, but from what I can tell, you are creating a class based on the
System.Web.UI.U serControl namespace and then, within that class, setting
some properties. That appears to be the same thing as using an interface. Is
that correct?
So based on that, would all of my controls that I want to dynamically load
then be based on this particular base class? And then, instead of loading
these as usercontrols, instead load them as usercontrol.myB aseClass?
-Darrel
I imagine you've figured it out by now, but here's what worked for me:
I created a base class:
Public Class BaseReportContr ol
Inherits System.Web.UI.U serControl
with properties and Overridable subs and functions that I might be
using in
the inherited controls.
Then to load one of the controls, I used:
Dim ctlReport As BaseReportContr ol
ctlReport = CType(LoadContr ol(SubReport), BaseReportContr ol)
where SubReport is a string like "ctl.ascx"
It's important to set the ID property if you're going to want to have
controls reloaded and functioning on postback. The point is to make
sure
a control has the same (arbitrary) value for ID every time.
darrel wrote: I posted an example of how to accomplish what you need in my answer
to your previous post. Did you have additional questions? I'm taking a second look at your example. It's in C#, so it's a bit
foreign to me, but from what I can tell, you are creating a class based on
the System.Web.UI.U serControl namespace and then, within that class,
setting some properties. That appears to be the same thing as using an
interface. Is that correct?
So based on that, would all of my controls that I want to dynamically
load then be based on this particular base class? And then, instead of
loading these as usercontrols, instead load them as usercontrol.myB aseClass?
-Darrel
Hello darrel,
Yes... an interface would work as well.
When you load them, you can do something like this:
[C#]
IMyControlInter face instance = (IMyControlInte rface)Page.Load Control("someco ntrol.ascx");
[VB]
Dim instance As IMyControlInter face
instance = CType(Page.Load Control("someco ntrol.ascx"), IMyControlInter face)
My VB.NET knowledge is non-existant, so the above may not be syntactically
correct, but you should get the idea.
--
Matt Berther http://www.mattberther.com I posted an example of how to accomplish what you need in my answer to your
previous post. Did you have additional questions? I'm taking a second look at your example. It's in C#, so it's a bit foreign to me, but from what I can tell, you are creating a class based on the System.Web.UI.U serControl namespace and then, within that class, setting some properties. That appears to be the same thing as using an interface. Is that correct?
So based on that, would all of my controls that I want to dynamically load then be based on this particular base class? And then, instead of loading these as usercontrols, instead load them as usercontrol.myB aseClass?
-Darrel
> I imagine you've figured it out by now, but here's what worked for me: I created a base class: Public Class BaseReportContr ol Inherits System.Web.UI.U serControl
with properties and Overridable subs and functions that I might be using in the inherited controls.
Then to load one of the controls, I used: Dim ctlReport As BaseReportContr ol ctlReport = CType(LoadContr ol(SubReport), BaseReportContr ol)
where SubReport is a string like "ctl.ascx"
It's important to set the ID property if you're going to want to have controls reloaded and functioning on postback. The point is to make sure a control has the same (arbitrary) value for ID every time.
Thanks! That helps! I think I got this working. I'll likely post a follow-up
question tomorrow.
-Darrel
> Yes... an interface would work as well.
Thanks for all the help, Matt. I think I got things working using the
base-class concept. I'll likely be posting a followup in the next day or two
;o)
-Darrel This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: james |
last post by:
I have a custom UserControl, which can have many sub class levels
derived from it. I want to be able to discover all the components at
Load time, but the only components I can see from the base class
are the private components internal to the base class itself. What
I want are ALL components for the entire class no matter how many
levels of sub-classing this particular control contains.
I do not want to have to force the child classes to...
|
by: Wysiwyg |
last post by:
I'm new to c# programming and can't figure out how to avoid duplicating
common code in multiple classes when I'm restricted to using different
system base classes.. I'm using c# in asp.net to write a web application but
this isn't specifically a web question.
I have two classes which must inherit a different System class, in a
specific case my web pages must inherit System.Web.UI.Page while my user
controls must inherit...
|
by: Davíð Þórisson |
last post by:
Please can someone tell me how on earth to create an instance of my top
level (base) Page class so that I can access it's objects from an user
control?? Someone told me
public myParent = (default_aspx) this.Page;
where default_aspx is the class name of the base Page...
|
by: Wade |
last post by:
Hi all,
We have created some "Base" class pages for our WebForms and UserControls.
For instance, when we create a WebForm called "WebForm1.aspx", instead of
inheriting from "System.Web.UI.Page" we implement from our "Base" class page
which itself inherits from "System.Web.UI.Page" -- I know, pretty standard.
We do the same with our UserControls, instead they inherit from
"System.Web.UI.UserControl".
Now, there are some methods that we...
|
by: Jackson |
last post by:
I want a class that will determine its base class by the argument passed
in. What I am about to write _does_not_work_, but it shows what I am
trying to do.
class ABC(some_super):
def __init__(self,some_super):
some_super.__init__(self)
if some_super == list:
self.append('ABC')
| |
by: Swami |
last post by:
I have 2 questions relating to website design in asp .net:
1. In a website that I am building I have everything as a user control. Even
the header, which contains the navigation tabs is in a user control which is
placed on every page. Originally, the reason why I chose to do it this way
(instead of placing the header in a master page) is because my header tabs
change dynamically based on who the user is. My question is, am I losing...
|
by: droyad |
last post by:
I have recently upgraded a web project from ASP.NET 1.1 to ASP.NET 2.0,
and now the event handlers no longer work, due to the event handlers
being defined in base classes.
To start a bit of background, below is a simplified example, but the
same design pattern is used for many other pages:
In the ASPX file a button is defined:
<asp:Button Runat="server" Text="Login" id="btnLogin"></asp:Button>
|
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 because I am not
always able to control/create all the different constructors the base
class has. My problem can be described in code as follows ...
/* This is the base class with a whole heap of
constructors/functionality*/
public class Animal
|
by: rjl444 |
last post by:
web developer express asp.net 2.0:
I need to have 3 user controls. these controls include a textbox and
several asp controls (checkbox, button, etc). I would like to have a
base class that defines these controls and then have 3 sub user
control classes refer to these controls. I am able to call methods in
the base class to work with data, but I cannot reference any of the
controls. How can I reference a textbox which is in a sub class...
|
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: 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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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: 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: 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();...
|
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: 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
| |
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...
| |