Access Eventhandler from Class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cornfed
    New Member
    • Oct 2007
    • 3

    Access Eventhandler from Class

    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:
    Code:
        public delegate void LinkButtonClickHandler(Object sender, EventArgs e);
    
        void NewsItem_DataBinding(object sender, EventArgs e)
        {
            lbLeesMeer.Click += new EventHandler(lbLeesMeer_Click);
            lbLeesMeer.ID = "lbLeesMeer" + Artikel_ID;
            lbLeesMeer.CommandArgument = TypeCode + ";" + Artikel_ID;
        }
    
        public static event LinkButtonClickHandler LinkButtonClick;
        protected void lbLeesMeer_Click(Object sender, EventArgs e)
        {
            if (LinkButtonClick != null) LinkButtonClick(sender, e);
        }
    In the page_load of the Aspx file where the eventhandler is:
    Code:
            if (!this.IsPostBack)
            {
                MyTemplate.LinkButtonClick += new LinkButtonClickHandler(lbMenu_click); //lbMenu_click is the Eventhandler I want to access
            }
    Anyone have some tips?
  • RedSon
    Recognized Expert Expert
    • Jan 2007
    • 4980

    #2
    Originally posted by 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:
    Code:
        public delegate void LinkButtonClickHandler(Object sender, EventArgs e);
    
        void NewsItem_DataBinding(object sender, EventArgs e)
        {
            lbLeesMeer.Click += new EventHandler(lbLeesMeer_Click);
            lbLeesMeer.ID = "lbLeesMeer" + Artikel_ID;
            lbLeesMeer.CommandArgument = TypeCode + ";" + Artikel_ID;
        }
    
        public static event LinkButtonClickHandler LinkButtonClick;
        protected void lbLeesMeer_Click(Object sender, EventArgs e)
        {
            if (LinkButtonClick != null) LinkButtonClick(sender, e);
        }
    In the page_load of the Aspx file where the eventhandler is:
    Code:
            if (!this.IsPostBack)
            {
                MyTemplate.LinkButtonClick += new LinkButtonClickHandler(lbMenu_click); //lbMenu_click is the Eventhandler I want to access
            }
    Anyone have some tips?
    This looks like ASP.Net with VB backend, what langauge are you using?

    I'm moving this to .NET.

    Comment

    • balabaster
      Recognized Expert Contributor
      • Mar 2007
      • 798

      #3
      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?

      Comment

      Working...