473,779 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.OnRaiseCFE vent(myArgs); code but in the OnRaiseCFEvent method
RaiseCFEVent is always null so this.RaiseCFEve nt(this,e); never executes.

Can anyone tell my why RaiseCFEvent is always null?
thanks,
T


public partial class EditGrid : System.Web.UI.U serControl
{
public delegate void ChangedFieldsEv entHandler(obje ct sender,
ChangedFieldsEv entArgs e);
public event ChangedFieldsEv entHandler RaiseCFEvent;
protected virtual void OnRaiseCFEvent( ChangedFieldsEv entArgs e)
{
if (this.RaiseCFEv ent != null)
{
this.RaiseCFEve nt(this,e);
}
}
..
..
..
ChangedFieldsEv entArgs myArgs = new
ChangedFieldsEv entArgs(gvRow.R owIndex, i, string1, string2);
this.OnRaiseCFE vent(myArgs);

..
..
..

}

public class ChangedFieldsEv entArgs : EventArgs
{
public readonly int row, col;
public readonly string newVal, oldVal;
public ChangedFieldsEv entArgs(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 1333
hi Tina
at a guess, your code goes something like this:

if(RaiseCFEVent != null)
this.RaiseCFEve nt(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.RaiseC FEvent += new EventHandler(th is.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**********@n ospamexcite.com wrote in message
news:ub******** ******@TK2MSFTN GP06.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.OnRaiseCFE vent(myArgs); code but in the OnRaiseCFEvent method
RaiseCFEVent is always null so this.RaiseCFEve nt(this,e); never executes.

Can anyone tell my why RaiseCFEvent is always null?
thanks,
T


public partial class EditGrid : System.Web.UI.U serControl
{
public delegate void ChangedFieldsEv entHandler(obje ct sender,
ChangedFieldsEv entArgs e);
public event ChangedFieldsEv entHandler RaiseCFEvent;
protected virtual void OnRaiseCFEvent( ChangedFieldsEv entArgs e)
{
if (this.RaiseCFEv ent != null)
{
this.RaiseCFEve nt(this,e);
}
}
.
.
.
ChangedFieldsEv entArgs myArgs = new
ChangedFieldsEv entArgs(gvRow.R owIndex, i, string1, string2);
this.OnRaiseCFE vent(myArgs);

.
.
.

}

public class ChangedFieldsEv entArgs : EventArgs
{
public readonly int row, col;
public readonly string newVal, oldVal;
public ChangedFieldsEv entArgs(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********@com munity.nospamwr ote in message
news:Og******** ******@TK2MSFTN GP03.phx.gbl...
hi Tina
at a guess, your code goes something like this:

if(RaiseCFEVent != null)
this.RaiseCFEve nt(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.RaiseC FEvent += new EventHandler(th is.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**********@n ospamexcite.com wrote in message
news:ub******** ******@TK2MSFTN GP06.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.OnRaiseCF Event(myArgs); code but in the OnRaiseCFEvent method
RaiseCFEVent is always null so this.RaiseCFEve nt(this,e); never executes.

Can anyone tell my why RaiseCFEvent is always null?
thanks,
T


public partial class EditGrid : System.Web.UI.U serControl
{
public delegate void ChangedFieldsEv entHandler(obje ct sender,
ChangedFieldsE ventArgs e);
public event ChangedFieldsEv entHandler RaiseCFEvent;
protected virtual void OnRaiseCFEvent( ChangedFieldsEv entArgs e)
{
if (this.RaiseCFEv ent != null)
{
this.RaiseCFEve nt(this,e);
}
}
.
.
.
ChangedFieldsEv entArgs myArgs = new
ChangedFieldsE ventArgs(gvRow. RowIndex, i, string1, string2);
this.OnRaiseCFE vent(myArgs);

.
.
.

}

public class ChangedFieldsEv entArgs : EventArgs
{
public readonly int row, col;
public readonly string newVal, oldVal;
public ChangedFieldsEv entArgs(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
1766
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 these events. The problem is: when using the WithEvents (Public WithEvents MyPersonnesDeContact As New System.Collections.Generic.List(Of clsPersonne)) I get an error, saying "'WithEvents' variable does not raise any events.".
6
2883
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 TimerState object similar to the example in the System.Threading.Timer documentation. The method which handles the timer events, among other things, periodically calls a method in this TimerState object which raises an event to the startup form,...
6
1765
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, however, I do know what ever it is I should be aware of it. currentcell_event(..) { ..
4
17270
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 maintain the reference to any module.
3
1956
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 the Managed C++ specifications, if one declares a public event without any attempt to provide one's own event access methods, clearly the most common case, the compiler generates public add_ and remove_ methods for the event and a protected raise_...
20
2421
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 line 1 and Thread B handles call activity on telephone line 2. They use a common SQL datasource, but all DataSets are unique to each thread. Is there a way for thread A to occasionally communication to thread B that something has happened? ...
3
3562
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 DoSomeWork While not Hungup Do lots of good things application.doevents end While
4
9813
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 raise an event on the main thread instead? TIA Charles
4
1546
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. In the constructor, I check the to see if the employees birthday is today. If it is today, then I raise an event.
1
1889
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 application, which uses other class libraries. One lib, called Utils.dll contains custom collection implementation. This simple collection just overrides Add and Remove methods to raise
0
9636
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8961
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.