Raise Event not working (revised)

T

Tina

(my last post was incomplete so this issue is being reposted)

I have an ASP.Net C# app with a Default.aspx page with an ascx user control
on the page named EditGrid.ascx given the ID myEG on the page.


I am trying to raise a custom event in this user control passing custom data
arguments. I have done this many times in VB but this is my first time in
C#.

In the default.aspx page I have the following code to subscribe to the event
along with an empty method to handle the event:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack){

myEG.RaiseCFEvent += new
EditGrid.ChangedFieldsEventHandler(this.HandleChangedEvent); }

}


protected void HandleChangedEvent(object sender, ChangedFieldsEventArgs
e)
{
string myString = "debug";
}


The code below, in the ascx control, passes the proper arguments in the
this.OnRaiseCFEvent(myArgs); code but in the OnRaiseCFEvent method
RaiseCFEVent is always null so this.RaiseCFEvent(this,e); never executes.

Can anyone tell my why RaiseCFEvent is always null? As you can see there is
a subscriber
to the event.
thanks,
T

public partial class EditGrid : System.Web.UI.UserControl
{
public delegate void ChangedFieldsEventHandler(object sender,
ChangedFieldsEventArgs e);
public event ChangedFieldsEventHandler RaiseCFEvent;
protected virtual void OnRaiseCFEvent(ChangedFieldsEventArgs e)
{
if (this.RaiseCFEvent != null)
{
this.RaiseCFEvent(this,e);
}
}
..
..
..
ChangedFieldsEventArgs myArgs = new
ChangedFieldsEventArgs(gvRow.RowIndex, i, string1, string2);
this.OnRaiseCFEvent(myArgs);

..
..
..

}

public class ChangedFieldsEventArgs : EventArgs
{
public readonly int row, col;
public readonly string newVal, oldVal;
public ChangedFieldsEventArgs(int row, int col, string newVal, string
oldVal)
{
this.row = row;
this.col = col;
this.newVal = newVal;
this.oldVal = oldVal;
}
}
 
J

john sun

Have you tried to put a breakpoint on this line...
myEG.RaiseCFEvent += new
EditGrid.ChangedFieldsEventHandler(this.HandleChangedEvent); }

and make sure the event is registered correctly.
 

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

Top