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

Dyanmically calling a function in usercontrol

phl
hi,

I have a number of usercontrols which inherits a interface. the
function in this interface is used to provide information about the
usercontrol. I would like to call this function say when a button is
clicked.

I can do this by lot of hardcoding, as I have the usercontrol names
stored and I can call this obligatory function like this:

//loop through list of usercontorls
foreach(BLL.TicketInfo ti in TicketInfo)
{
if(ti.UserControlName.ToLower() == "EditProfile.ascx".ToLower())
{
EditProfile uc = (EditProfile)CurPage.FindControl("EditProfile");
dv.AddRange(uc.GetDisabledValidators());
}

//etc
}

while this works, it's crap because it makes adding usercontrols to my
app inconvienientm as I have to add hardcoded stuff everywhere. Just
wondering if you guys knows of a smarter way of doing this, like
dynamically. If I somehow loaded the usercontorl with the string I
have, should I be able query the function it supports by the interface
it's has inherited?

Cheers

Nov 19 '05 #1
3 1257
"phl" <ki************@hotmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
hi,

I have a number of usercontrols which inherits a interface. the
function in this interface is used to provide information about the
usercontrol. I would like to call this function say when a button is
clicked.

I can do this by lot of hardcoding, as I have the usercontrol names
stored and I can call this obligatory function like this:

//loop through list of usercontorls
foreach(BLL.TicketInfo ti in TicketInfo)
{
if(ti.UserControlName.ToLower() == "EditProfile.ascx".ToLower())
{
EditProfile uc = (EditProfile)CurPage.FindControl("EditProfile");
dv.AddRange(uc.GetDisabledValidators());
}

//etc
}

while this works, it's crap because it makes adding usercontrols to my
app inconvienientm as I have to add hardcoded stuff everywhere. Just
wondering if you guys knows of a smarter way of doing this, like
dynamically. If I somehow loaded the usercontorl with the string I
have, should I be able query the function it supports by the interface
it's has inherited?


You can loop through all the controls on your page (or panel, or whatever).
You can test to see if you have one of your user controls by checking for
the interface:

foreach (Control c in this.Controls)
{
if (c is IMyInterface)
{
((IMyInterface) c).MyFunction();
}
}

John Saunders
Nov 19 '05 #2
You can loop through them and do:

if (control is IUserControlDetail){
string value = ((IUserControlDetail)control).GetDetails();
}

where IUserControlDetail is the interface and GetDetails() is defined by
said interface..

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"phl" <ki************@hotmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
hi,

I have a number of usercontrols which inherits a interface. the
function in this interface is used to provide information about the
usercontrol. I would like to call this function say when a button is
clicked.

I can do this by lot of hardcoding, as I have the usercontrol names
stored and I can call this obligatory function like this:

//loop through list of usercontorls
foreach(BLL.TicketInfo ti in TicketInfo)
{
if(ti.UserControlName.ToLower() == "EditProfile.ascx".ToLower())
{
EditProfile uc = (EditProfile)CurPage.FindControl("EditProfile");
dv.AddRange(uc.GetDisabledValidators());
}

//etc
}

while this works, it's crap because it makes adding usercontrols to my
app inconvienientm as I have to add hardcoded stuff everywhere. Just
wondering if you guys knows of a smarter way of doing this, like
dynamically. If I somehow loaded the usercontorl with the string I
have, should I be able query the function it supports by the interface
it's has inherited?

Cheers

Nov 19 '05 #3
the control is passed to the event as sender. you can just cast to the
interface and call the methods.

protected void button1_click(object sender, EventArgs e)
{
myInterface mybtn = sender as myInterface;
if (mybtn != null)
{
// call interface methods
}
}

-- bruce (sqlwork.com)
"phl" <ki************@hotmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
| hi,
|
| I have a number of usercontrols which inherits a interface. the
| function in this interface is used to provide information about the
| usercontrol. I would like to call this function say when a button is
| clicked.
|
| I can do this by lot of hardcoding, as I have the usercontrol names
| stored and I can call this obligatory function like this:
|
| //loop through list of usercontorls
| foreach(BLL.TicketInfo ti in TicketInfo)
| {
| if(ti.UserControlName.ToLower() == "EditProfile.ascx".ToLower())
| {
| EditProfile uc = (EditProfile)CurPage.FindControl("EditProfile");
| dv.AddRange(uc.GetDisabledValidators());
| }
|
| //etc
| }
|
| while this works, it's crap because it makes adding usercontrols to my
| app inconvienientm as I have to add hardcoded stuff everywhere. Just
| wondering if you guys knows of a smarter way of doing this, like
| dynamically. If I somehow loaded the usercontorl with the string I
| have, should I be able query the function it supports by the interface
| it's has inherited?
|
| Cheers
|
Nov 19 '05 #4

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

Similar topics

3
by: Dave McCracken | last post by:
I am hosting .Net UserControls in HTML pages with Object Tags. These UserControls are clients of remotable objects that run on the same machine. The remote objects execute callbacks via sponsor...
3
by: David N | last post by:
Hi All, I just wonder if in C#, I can develop a user defined control that can call its parent function which is not yet developed. For example, how do I make my user control call a...
3
by: MattB | last post by:
I have a UserControl that I use as a page header for my app. I want it to vary depending on what page it's being called by. In the CodeBehind, how to I refer to the calling page? Thanks! -- ...
3
by: NWx | last post by:
Hi, I defined a base class, Panel, based on System.Web.UI.UserControl, as below: Public MustInherit Class Panel Inherits System.Web.UI.UserControl ..... In another module, I want to...
1
by: JezB | last post by:
In my Page_Load event of all my web app Pages and UserControls I instantiate the same library class "TextResources" (to take care of reading presentation text strings from localizable resource...
3
by: Peter Rilling | last post by:
Okay, I am probably missing something simple so here is my problem. I have a page. On this page I have a usercontrol. On this user control I have another usercontrol. On each usercontrol I...
2
by: ryanmhuc | last post by:
Is it possible to dyanmically call a classes static member or property? So something like class test1 { static $staticVar = "Help"; } $className = "test1"; echo $className::$staticVar;
2
by: fillic2002 | last post by:
Hi I have a query related to the VS2005 usercontrol. As i have two different usercontrol in a single master page say uc1 and uc2. Now i am calling a function of uc1 from uc2. what is the best...
3
by: Bert | last post by:
Hi How can you call a function on a user control(.ascx) ? what is the syntax for this? thanks Bert
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
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,...
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...
1
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...
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...
0
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...
0
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...

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.