Hi there,
You can handle an event only if you subscribed to it. Technically,
subscribing/handling means passing a method pointer to the event source:
Page.Load += new EventHandler(th is.Page_Load);
If you have programmed in C or C++ is similar to this
void* (*EventHandler) (object* source, EventArgs* e);
this.Load = &this.Page_Load ;
or if you programmed in Delphi Object Pascal it is equivalent to:
Page.Load := self.Page_Load;
I used similar because .NET events employ multicast delegates that are
‘collectionsâ €™ of method pointer so many subscribers can handle one event.
Anyway
>1. A component on a webusercontrol fires a postback event. On >postback the parent page handles that event and runs code >specifically for that page. So that the same event can run different >code depending on what page it is on.
Yes. Behind the scenes there’s always a statement that attaches event
handler to particular event. In ASP.NET 1.1, everything was explicitly
assigned in InitializeCompo nent() method. ASP.NET 2.0 (by default),
implicitly attaches event handlers for you based on naming convention and
AutoEventWireup @page attribute. For example, AutoEventWireup =true and page
compiler discovers there is a protected/public method called Page_Load(objec t
sender, EventArgs e), it automatically does assignment
Page.Load += new EventHandler(th is.Page_Load);
>2. A component on a webusercontrol fires a postback event and >another webusercontrol on that page recognises that event was fired >and runs its own method.
It doesn’t recognize, it just attaches an event handler as stated above.
Hope it’s clear now
Milosz
"Jeremy Martin" wrote:
>
Hi,
I am currently learning c# so be gentle :)
I am converting a Delphi.NET website to c# website and I am confused as
to how events are handled.
2 Situations.
1. A component on a webusercontrol fires a postback event. On postback
the parent page handles that event and runs code specifically for that
page. So that the same event can run different code depending on what
page it is on.
2. A component on a webusercontrol fires a postback event and another
webusercontrol on that page recognises that event was fired and runs
its own method.
I hope this is enough information because I only know how it works in
Delphi.
Many Thanks
Jeremy