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
    ReprotList.ascx.cs.

    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
    OnFunctionalAreaChanged.
    private void dropFunctions_SelectedIndexChanged(object sender,
    System.EventArgs e)
    {
    OnFunctionalAreaChanged();
    }

    protected void OnFunctionalAreaChanged()
    {
    if(FunctionalAreaChanged != null)
    {
    FunctionalAreaChanged(this, new
    Globals.FunctionalAreaEventArgs(dropFunctions.SelectedValue));
    }
    }

    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
    Globals.FunctionalAreaChangedHandler(this.OnFunctionChanged);
    }

    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
    missing?

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

  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
    http://www.OdeToCode.com/blogs/scott/


    On Fri, 3 Jun 2005 09:26:53 -0500, "Luis Esteban Valencia Muñoz"
    <> wrote:

    >Hello Experts,
    >
    >I have three classes: Globals.cs, FunctionalArea.ascx.cs, and
    >ReprotList.ascx.cs.
    >
    >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
    >OnFunctionalAreaChanged.
    >private void dropFunctions_SelectedIndexChanged(object sender,
    >System.EventArgs e)
    >{
    > OnFunctionalAreaChanged();
    >}
    >
    >protected void OnFunctionalAreaChanged()
    >{
    > if(FunctionalAreaChanged != null)
    > {
    > FunctionalAreaChanged(this, new
    >Globals.FunctionalAreaEventArgs(dropFunctions.SelectedValue));
    > }
    >}
    >
    >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
    >Globals.FunctionalAreaChangedHandler(this.OnFunctionChanged);
    >}
    >
    >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
    >missing?
    >
    >Thanks for your help!
    >
    Scott Allen, Jun 3, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?ZGFuYw==?=

    DataGrid ItemCommand event not firing if not first page

    =?Utf-8?B?ZGFuYw==?=, Oct 26, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    4,141
    =?Utf-8?B?ZGFuYw==?=
    Oct 26, 2005
  2. GauravGupta
    Replies:
    4
    Views:
    2,084
    Shilpa1234
    Jan 19, 2012
  3. Anthony Papillion

    TkInter bind() event is not firing event trigger

    Anthony Papillion, Jun 23, 2010, in forum: Python
    Replies:
    3
    Views:
    1,659
    rantingrick
    Jun 23, 2010
  4. Don
    Replies:
    1
    Views:
    254
    mr fox
    May 16, 2005
  5. Ryan Rueckl

    DataGris Paging not working (event not firing)

    Ryan Rueckl, Jun 22, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    8
    Views:
    188
    Ryan Rueckl
    Jun 24, 2005
Loading...

Share This Page