473,503 Members | 1,648 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Call Base Class Method from Dynamic User Control

149 New Member
I've been reading up on delegates and BubbleEvents but this doesn't seem to be the answer to my simple problem.

I have a method in my base class which I would like to call from a dynamically loaded user control after it has executed some other code.

The method in my base class cannot be a static method (making it accessible to my user control) because it relies on other methods in the base class.

Do I need to create a delegate for this method or a bubble event?

Can somebody please point me in the right direction.
Oct 9 '07 #1
2 1905
rsdev
149 New Member
I've read tons of literature and consulted my pro c#/ASP.NET books.

I have this code in my user control.

Expand|Select|Wrap|Line Numbers
  1. public event EventHandler BubbleClick;
  2.         protected void OnBubbleClick(EventArgs e)
  3.         {
  4.             if (BubbleClick != null)
  5.             {
  6.                 BubbleClick(this, e);
  7.             }
  8.         }
When I load the control dynamically I want to add a new EventHandler to the user control.

But BubbleClick is not a definition of UserControl so how do I assign an EventHandler to it?

Totally stumped. Here's the bit that's not working.

Expand|Select|Wrap|Line Numbers
  1. while (i < compLength)
  2.             {
  3.                 string compPath = "_components/" + compType[i].Type + ".ascx";
  4.                 UserControl compControl = (UserControl)Page.LoadControl(compPath);
  5.                 compControl.ID = Convert.ToString(compType[i].CompId);
  6.                 //PlaceHolder plcName = (PlaceHolder)Master.FindControl("MainContent").FindControl("PlaceHolderName" + compType[i].PlaceHolder.ToString()); //Find all PlaceHolders - names PlaceHolderName0, PlaceHolderName1...
  7.                 PlaceHolder plcName = (PlaceHolder)findControl("PlaceHolderName" + compType[i].PlaceHolder.ToString(), Master);
  8.                 plcName.Controls.Add(compControl);
  9.                 if (compControl.ID == "1")
  10.                 {
  11.  
  12.                    compControl.BubbleClick += new EventHandler(BtnCloseEditMode_Click);
  13.                 }
  14.                 i++;
  15.             }
Oct 9 '07 #2
rsdev
149 New Member
The problem with the above code is that BubbleClick is not a definition of UserControl. So how do I declare this?

Your help would be greatly appreciated.
Oct 9 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

39
6477
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
9
3649
by: Daniel Kay | last post by:
Hello! I have written two template classes which implement the observerpattern in C++. I hope I manage to desribe the problem I have. template<class T> class Observer { /* ... */ }; ...
3
11857
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
2268
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....
6
1391
by: Karl Hungus | last post by:
Im using an xsl transformation so its not practical to use controls in the usual way, but I would still like to call methods in my codebehind class. usually Id just use onclick="<eventHandler>"...
10
6018
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 =...
3
5488
by: Tom | last post by:
Can I dynamic call vb.net object such like vb6 as sample dim A as object set a = createobject("myobject.test") a.open() now mypbject.test is create vb.net . How can I dynamic call without...
3
3960
by: forest demon | last post by:
for example, let's say I do something like, System.Diagnostics.Process.Start("notepad.exe","sample.txt"); if the user does a SaveAs (in notepad), how can i capture the path that the user...
26
5333
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
7198
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
7072
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
7271
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
7319
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
4666
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
3160
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...
0
3149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
373
bsmnconsultancy
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...

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.