PC Review


Reply
Thread Tools Rate Thread

C# Event Raising Problem

 
 
Tina
Guest
Posts: n/a
 
      27th Aug 2006
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;
}
}


 
Reply With Quote
 
 
 
 
Tim_Mac
Guest
Posts: n/a
 
      27th Aug 2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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;
> }
> }
>



 
Reply With Quote
 
Tina
Guest
Posts: n/a
 
      27th Aug 2006
I'm doing that. Please see my repost.
Thanks for responding.
T

"Tim_Mac" <(E-Mail Removed)> wrote in message
news:Og$(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>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;
>> }
>> }
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
c# Event raising problem (revised) Tina Microsoft ASP .NET 2 28th Aug 2006 12:02 AM
Raising event =?Utf-8?B?UGV0ZXIgU2NobWl0eg==?= Microsoft Dot NET 3 23rd Feb 2005 11:21 PM
App sporadically hangs while raising event while processing system.threading.timer event Dan Microsoft Dot NET Compact Framework 6 25th Oct 2004 09:38 PM
App sporadically hangs while raising event while processing system.threading.timer event Dan Microsoft C# .NET 6 25th Oct 2004 09:38 PM
Raising a tab event Top Gun Microsoft Dot NET 0 12th Feb 2004 01:43 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:35 AM.