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

Access Eventhandler from Class

cornfed
I've got a class to make Templates for different repeaters in my page. in one of these repeaters a linkbutton is needed. This LinkButton needs an event that is in a .cs file somewhere else in the website. (coz the event is used by other controls too) In the event some of the controls of that page ar accessed so I thought it would be easy to keep the Eventhandler there too.

My problem is that I cant seem to get the eventhandler to work. Basic code in the cass is

In the Class:
Expand|Select|Wrap|Line Numbers
  1.     public delegate void LinkButtonClickHandler(Object sender, EventArgs e);
  2.  
  3.     void NewsItem_DataBinding(object sender, EventArgs e)
  4.     {
  5.         lbLeesMeer.Click += new EventHandler(lbLeesMeer_Click);
  6.         lbLeesMeer.ID = "lbLeesMeer" + Artikel_ID;
  7.         lbLeesMeer.CommandArgument = TypeCode + ";" + Artikel_ID;
  8.     }
  9.  
  10.     public static event LinkButtonClickHandler LinkButtonClick;
  11.     protected void lbLeesMeer_Click(Object sender, EventArgs e)
  12.     {
  13.         if (LinkButtonClick != null) LinkButtonClick(sender, e);
  14.     }
  15.  
In the page_load of the Aspx file where the eventhandler is:
Expand|Select|Wrap|Line Numbers
  1.         if (!this.IsPostBack)
  2.         {
  3.             MyTemplate.LinkButtonClick += new LinkButtonClickHandler(lbMenu_click); //lbMenu_click is the Eventhandler I want to access
  4.         }
  5.  
Anyone have some tips?
Oct 26 '07 #1
2 1456
RedSon
5,000 Expert 4TB
I've got a class to make Templates for different repeaters in my page. in one of these repeaters a linkbutton is needed. This LinkButton needs an event that is in a .cs file somewhere else in the website. (coz the event is used by other controls too) In the event some of the controls of that page ar accessed so I thought it would be easy to keep the Eventhandler there too.

My problem is that I cant seem to get the eventhandler to work. Basic code in the cass is

In the Class:
Expand|Select|Wrap|Line Numbers
  1.     public delegate void LinkButtonClickHandler(Object sender, EventArgs e);
  2.  
  3.     void NewsItem_DataBinding(object sender, EventArgs e)
  4.     {
  5.         lbLeesMeer.Click += new EventHandler(lbLeesMeer_Click);
  6.         lbLeesMeer.ID = "lbLeesMeer" + Artikel_ID;
  7.         lbLeesMeer.CommandArgument = TypeCode + ";" + Artikel_ID;
  8.     }
  9.  
  10.     public static event LinkButtonClickHandler LinkButtonClick;
  11.     protected void lbLeesMeer_Click(Object sender, EventArgs e)
  12.     {
  13.         if (LinkButtonClick != null) LinkButtonClick(sender, e);
  14.     }
  15.  
In the page_load of the Aspx file where the eventhandler is:
Expand|Select|Wrap|Line Numbers
  1.         if (!this.IsPostBack)
  2.         {
  3.             MyTemplate.LinkButtonClick += new LinkButtonClickHandler(lbMenu_click); //lbMenu_click is the Eventhandler I want to access
  4.         }
  5.  
Anyone have some tips?
This looks like ASP.Net with VB backend, what langauge are you using?

I'm moving this to .NET.
Nov 2 '07 #2
balabaster
797 Expert 512MB
I for one don't understand the question...so let me recap what I think I understood:

You are trying to access an event from a class that you haven't directly instantiated? i.e. this event is in some class buried elsewhere in your website and when this event is fired it needs to affect the web page that is currently viewed? If I understood the question correctly, I can't comprehend a situation where this would be useful...and consequently can't wrap my head around providing an answer...

Can you clarify?
Nov 2 '07 #3

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

Similar topics

0
by: dominosly | last post by:
Okay, this is a rather complicated problem, so here is the short of it: I am using a custom designed user control that simply writes out a plain old html submit button to the page. When the...
3
by: Anonymous | last post by:
Hi, I have the following code. ( Sorry if it is a little rough or improperly written ). <########## CODE BEGIN ##########> public class TestClass : System.Windows.Forms.UserControl { public...
1
by: Abareblue | last post by:
I have no clue on how to insert a record into access. here is the whole thing using System; using System.Drawing; using System.Collections; using System.ComponentModel;
12
by: aplaxas | last post by:
Hi! "CDemo.Call" eventHandler is added to "button3.click" Event when both button1 and button2 are clicked. However, I want to add "cd.Call" only one time even though I clicked both button1 and...
4
by: theo | last post by:
Program flow...load file,then extract the xml text tags from the file,then the number of Xml tags retrieved from the file determines the number of dropdownlist controls instanciated in the...
2
by: paul meaney | last post by:
All, myself and another developer have been staring blankly at a screen for the past 48 hours and are wondering just what stunningly obvious thing we are missing. We are trying to load up 2...
29
by: Patrick | last post by:
I have the following code, which regardless which works fine and logs to the EventViewer regardless of whether <processModel/> section of machine.config is set to username="SYSTEM" or "machine" ...
7
by: sam.m.gardiner | last post by:
I'm working with VB.NET events and I want a way to disconnect all the handlers of an event. I want to do this in the object that is the source of the event. This is slightly tricky in VB.Net as the...
0
by: bharathreddy | last post by:
Here I will given an example on how to access the session, application and querystring variables in an .cs class file. Using System.Web.HttpContext class. 1) For accesing session variables :...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
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?

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.