• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 223
  • Last Modified:

Why am I getting a null for the event handler in an asp.net user control?

I am trying to construct a user control in C# ASP.NET

On the user control there is a button
IndustryShowButton

All is working well except, when I click this button I get the event handler  IndustryShowButtonClicked is null

See the code attached

Thanks
Stuart
using System;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ZZ_Development_Controls_IndustryUserControl : UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DefineButtonClicks();
    }  

//Other Code………………………………………………………
  
  
    protected void DefineButtonClicks()
    {
        IndustryShowButton.Click += new System.EventHandler(this.IndustryShowButton_OnClick);
    }

    public event IndustryControlEventHandler IndustryShowButtonClicked;


    // On show button click create object and fire  
    protected void IndustryShowButton_OnClick(object sender, EventArgs e)
    {
        bool showButtonClicked = true;
        IndustryControlEventArgs args = new IndustryControlEventArgs(showButtonClicked);
        IndustryShowButtonClicked(this, args);
    }
}


public class IndustryControlEventArgs : EventArgs
{
    public IndustryControlEventArgs(bool item)
    {
        showHide = item;
    }
    
    private bool showHide;
    public bool ShowHide
    {
        get { return showHide; }
    }
}

public delegate void IndustryControlEventHandler(object sender, IndustryControlEventArgs e);

Open in new window

0
Stuart_Laird
Asked:
Stuart_Laird
1 Solution
 
käµfm³d 👽Commented:
Attach the handler in the Init method:

protected override void OnInit(EventArgs e)
{
    DefineButtonClicks();
}

Open in new window

0
 
Stuart_LairdAuthor Commented:
Thanks
0
 
Amandeep Singh BhullarCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now