Event not firing

Discussion in 'ASP .Net' started by Luis Esteban Valencia Muñoz, Jun 3, 2005.

  1. Hello Experts,

    I have three classes: Globals.cs, FunctionalArea.ascx.cs, and

    The idea is that when one drop down is changed (i.e. Functional Area),
    another drop down on the page (Reports) would get updated. Both of theses
    are controls in the same web form.

    In Globals.cs:

    public delegate void FunctionalAreaChangedHandler(object sender,
    FunctionalAreaEventArgs args);

    public class FunctionalAreaEventArgs : EventArgs
    private string _functionalArea = string.Empty;

    public FunctionalAreaEventArgs(string functionalArea)
    _functionalArea = functionalArea;

    public string getFunctionalArea
    get { return _functionalArea; }

    In FunctionalArea.ascx.cs:

    public event Globals.FunctionalAreaChangedHandler FunctionalAreaChanged;

    // When the user changes the Funcational Area drop down, run
    private void dropFunctions_SelectedIndexChanged(object sender,
    System.EventArgs e)

    protected void OnFunctionalAreaChanged()
    if(FunctionalAreaChanged != null)
    FunctionalAreaChanged(this, new

    In ReprotList.ascx.cs:

    private FunctArea _functArea = new FunctArea();

    private void OnFunctionChanged(object sender,
    Globals.FunctionalAreaEventArgs args)
    Response.Write("Delegate worked!");
    Response.Write("<script>alert('Delegate Worked!');</script>");

    private void InitializeComponent()
    this._functArea.FunctionalAreaChanged += new

    Unfortunately, the event does not seem to be firing since
    "if(FunctionalAreaChanged != null)" always returns false in
    FunctionalArea.ascx.cs (i.e. FunctionalAreaChanged == null).

    Where is "FunctionalAreaChanged" supposed to be assigned a value? What am I

    Thanks for your help!
    Luis Esteban Valencia Muñoz, Jun 3, 2005
    1. Advertisements

  2. Luis Esteban Valencia Muñoz

    Scott Allen Guest

    I believe the problem you are seeing is two different instances of
    FunctArea. One will be the control ASP.NET instantiates on the page -
    and the other FunctArea object is one you are creating in the code
    behind. Isn't FunctArea the control derived from UserControl? If it
    is, you don't want to instantiate the control yourself with the new
    operator, let ASP.NET hook it up to the control on the page.
    Scott Allen, Jun 3, 2005
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.