Event not firing

  • Thread starter Luis Esteban Valencia Muñoz
  • Start date
L

Luis Esteban Valencia Muñoz

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!
 
S

Scott Allen

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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top