That is what I wanted to avoid actually. But it may be the only way I can
achieve what I want to do. I do similar stuff elsewhere but it doesn't seem
as elegant as just doing it all with events and not making methods that
iterate over all the controls when each control could just subscribe the the
event as needed.
I would rather do this with pure events. It seems that if you don't derive
from a base class then event handling is 1:1. However, as soon as I started
deriving then the whole event model blew up because nothing can see the
other's events. Which seems counterintuitive.
Thanks for the input - any other ideas?
"Sergey Gorbachev" wrote:
> >Likewise I cannot construct a handles in the controls because
> >they cannot see the page event.
> > Any ideas or need for further info?
>
> What about this idea:
>
> 1. You define a Notification List (NL) on the page for each event you need
> to handle (or one list for all events):
>
> public ArrayList NotificationList = new ArrayList();
>
> 2. Each UC has one base class, wich in its OnLoad method registers itself in
> the NL:
>
> public class MyBaseControl: UserControl
> {
> override OnLoad()
> {
> if (Page != null) (Page as MyBasePage).NotificationList.Add(this);
> }
>
> public HandlePageEvent(EventArgs e)
> {
> DoSomething();
> }
> }
>
> 3. When you have an event on a page, you do something like this:
>
> protected MyList_SelectedIndexChanged(EventArgs e)
> {
> foreach (MyBaseControl control in NotificationList)
> control.HandlePageEvent(e);
> }
>
> So, all your UC will see the page's events.
>
> PS. I typed directly into this window, so, it is a "psevdocode".
>
>
>
|