473,385 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

C# Event Raising Problem

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

The code below 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?
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;
}
}
Aug 26 '06 #1
2 1319
hi Tina
at a guess, your code goes something like this:

if(RaiseCFEVent != null)
this.RaiseCFEvent(args);

and you are wondering why the RaiseCFEVent delegate is null? if this is
null, it means nobody is listening for the event.
if you want some code to listen to the event, use code like this:

MyObject.RaiseCFEvent += new EventHandler(this.RaiseCFEvent_Handler);

where MyObject is the object that contains the event delegate. it may help
to open up the debugger in VS and examine the RaiseCFEvent delegate before
and after you add your event handlers, you will be able to see if any
handlers are wired up to it.

hope this helps.
tim
--
------------------------------------------
blog: http://tim.mackey.ie
"Tina" <Ti**********@nospamexcite.comwrote in message
news:ub**************@TK2MSFTNGP06.phx.gbl...
>I am trying to raise a custom event in a user control passing custom data
arguments. I have done this many times in VB but this is my first time in
C#.

The code below 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?
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;
}
}

Aug 27 '06 #2
I'm doing that. Please see my repost.
Thanks for responding.
T

"Tim_Mac" <ti********@community.nospamwrote in message
news:Og**************@TK2MSFTNGP03.phx.gbl...
hi Tina
at a guess, your code goes something like this:

if(RaiseCFEVent != null)
this.RaiseCFEvent(args);

and you are wondering why the RaiseCFEVent delegate is null? if this is
null, it means nobody is listening for the event.
if you want some code to listen to the event, use code like this:

MyObject.RaiseCFEvent += new EventHandler(this.RaiseCFEvent_Handler);

where MyObject is the object that contains the event delegate. it may
help to open up the debugger in VS and examine the RaiseCFEvent delegate
before and after you add your event handlers, you will be able to see if
any handlers are wired up to it.

hope this helps.
tim
--
------------------------------------------
blog: http://tim.mackey.ie
"Tina" <Ti**********@nospamexcite.comwrote in message
news:ub**************@TK2MSFTNGP06.phx.gbl...
>>I am trying to raise a custom event in a user control passing custom data
arguments. I have done this many times in VB but this is my first time in
C#.

The code below 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?
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;
}
}


Aug 27 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: DraguVaso | last post by:
Hi, I have a Generic List, for instance: Public MyPersonnesDeContact As New System.Collections.Generic.List(Of clsPersonne) My clsPersonne raises some events, and I want to be able to handle...
6
by: Dan | last post by:
I've created a pocketpc app which has a startup form containing a listview. The form creates an object which in turn creates a System.Threading.Timer. It keeps track of the Timer state using a...
6
by: Steve B. | last post by:
Is it good programming practice to call an event within an event? I'm I creating recursion somehow somewhere? Does an event (e.g. send, e) ever end? I'm sorry, I'm not sure I know what I mean,...
4
by: rawCoder | last post by:
Hi all, How Can You Raise Events Asynchronously ? Now for the details ... I want to do inter modular communication using events in such a way that the contributing modules need not...
3
by: Edward Diener | last post by:
According to the CLS specification, the accessibility of the methods for adding, removing, and raising an event must be identical. There appear to be a few problems with this: 1) According to...
20
by: Bob Day | last post by:
Using VS 2003, VB, MSDE... There are two threads, A & B, that continously run and are started by Sub Main. They instantiationsl of identical code. Thread A handles call activity on telephone...
3
by: bclegg | last post by:
Hi, I am trying to use a 3rd Party telephony (Intel's CT-ADE 8.3) library in a vb.net service. The way it hangs up is to raise an Event. If you build a windows Application you can write: Sub...
4
by: Charles Law | last post by:
Suppose a worker thread needs to signal to the main thread that an event has occurred. Ordinarily, any event raised by the worker thread will be on its own thread. How can the worker thread...
4
by: sloan | last post by:
I"m trying to figure out what concept I'm missing here, or if its not a good idea .. or what. Here is my example.. code is below. I have an employee class. It has an event that can be raised....
1
by: Asko Telinen | last post by:
Hi all. I ran into quite strange problem concerning the event raising inside FileSystemWatcher Delete event. First, i would like to describe a bit my environment. I have main GUI...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.