473,785 Members | 2,283 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

c# Event raising problem (revised)

(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(objec t sender, EventArgs e)
{
if (!IsPostBack){

myEG.RaiseCFEve nt += new
EditGrid.Change dFieldsEventHan dler(this.Handl eChangedEvent); }

}
protected void HandleChangedEv ent(object sender, ChangedFieldsEv entArgs
e)
{
string myString = "debug";
}
The code below, in the ascx control, 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? As you can see there is
a subscriber
to the event.
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 #1
2 2173

Hi Tina,

the code looks neat except for the fact : event should be assigned in the
OnInit() not OnLoad().

Move

myEG.RaiseCFEve nt += new
EditGrid.Change dFieldsEventHan dler(this.Handl eChangedEvent); }

in the default.aspx.cs to

override protected void OnInit(EventArg s e)
{
InitializeCompo nent();
base.OnInit(e);
}

private void InitializeCompo nent()
{
myEG.RaiseCFEve nt += new
ChangedFieldsEv entHandler(this .HandleChangedE vent);
this.Load += new System.EventHan dler(this.Page_ Load);
}

Thanks,
Sazid.

"Tina" wrote:
(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(objec t sender, EventArgs e)
{
if (!IsPostBack){

myEG.RaiseCFEve nt += new
EditGrid.Change dFieldsEventHan dler(this.Handl eChangedEvent); }

}
protected void HandleChangedEv ent(object sender, ChangedFieldsEv entArgs
e)
{
string myString = "debug";
}
The code below, in the ascx control, 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? As you can see there is
a subscriber
to the event.
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
oh, you know what, I had the subscription code after my postback test. I
just had to move it up above so I resubscribe
on each postback. And, your solution would have worked too.

Thanks for your help.
T

"Sazid Khan" <Sa*******@disc ussions.microso ft.comwrote in message
news:0A******** *************** ***********@mic rosoft.com...
>
Hi Tina,

the code looks neat except for the fact : event should be assigned in the
OnInit() not OnLoad().

Move

myEG.RaiseCFEve nt += new
EditGrid.Change dFieldsEventHan dler(this.Handl eChangedEvent); }

in the default.aspx.cs to

override protected void OnInit(EventArg s e)
{
InitializeCompo nent();
base.OnInit(e);
}

private void InitializeCompo nent()
{
myEG.RaiseCFEve nt += new
ChangedFieldsEv entHandler(this .HandleChangedE vent);
this.Load += new System.EventHan dler(this.Page_ Load);
}

Thanks,
Sazid.

"Tina" wrote:
>(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(objec t sender, EventArgs e)
{
if (!IsPostBack){

myEG.RaiseCFEve nt += new
EditGrid.Chang edFieldsEventHa ndler(this.Hand leChangedEvent) ; }

}
protected void HandleChangedEv ent(object sender,
ChangedFieldsE ventArgs
e)
{
string myString = "debug";
}
The code below, in the ascx control, 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? As you can see there
is
a subscriber
to the event.
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

5
1585
by: Santhoshi | last post by:
I have an event declared in class1 Now i want to raise the event in the my class2 or anywhere other than class1 Is it possible? If so how Thank you
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_...
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
9814
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
4608
by: Phil Townsend | last post by:
I have an application that needs to respond to events that occur outside of the application itself. My project, called "ShowDetection" declares the event. I have a console app called "TestEvent" that I would like to use to test the event handler. Any action in the console app would be acceptable, such as a keystroke. I am at a loss on how to go about detecting and raising this event in my Winform. cn anybody help? Thanks!
0
9483
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
10346
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10157
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
9956
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8982
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...
1
7504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6742
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();...
1
4055
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
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.