Ask a Question related to ASP.NET Building Controls, Design and Development.
-
Phil #1
Global Events that all instances of a control handles
I have a user control (called MyControl that inherits from
CompositeControl). This control will raise an event when the user changes
the color of the control. (MyControl.ColorChange). Inside the code for
MyControl, I also listen and handle the event (ColorChange). - This actually
implements the change in color. This works OK for the control that raised
the event.
However, in the aspx form, I have 5 instances of the same user control
(MyControl). When one of the controls change color (based on user input) I
would like to have each instance of the MyControl listen for the event and
handle the ChangeColor event. When I try this only the control that raised
the event will hear the event. Is there any way to globally raise an event
that all controls could listen too?
Thanks
Phil
Phil Guest
-
Odd web control problem. Two instances of control A on different pages display each other's data!
I am currently using the ScottWatter (or ScottWater) Amazon Book Control in a website I am developing. Basically this is the outline: - It is a... -
Notify child control of events in parent control
I have a parent control that has a imagebutton on it, with code to handle the click event. I also have various ascx controls that are loaded by the... -
Under what context Application events run in Global.asax
(I am running .NET Framework 1.1) I have a timer(System.Timers.Timer) running in my Global.asax page. In the timer.elapsed event I am trying to... -
Multiple instances of a control? <img> ??
Is it possible to have multiple instances of a control and still access all of them in codebehind? For example, I need to be able to change an... -
Name of events in Global.asax
Hi. Reading the docs about the Global.asax events I noticed the names used on the help are not the same on the file. For example, the docs talk... -
Phil #2
Global Events that all instances of a control handles
I have a user control (called MyControl that inherits from
CompositeControl). This control will raise an event when the user changes
the color of the control. (MyControl.ColorChange). Inside the code for
MyControl, I also listen and handle the event (ColorChange). - This actually
implements the change in color. This works OK for the control that raised
the event.
However, in the aspx form, I have 5 instances of the same user control
(MyControl). When one of the controls change color (based on user input) I
would like to have each instance of the MyControl listen for the event and
handle the ChangeColor event. When I try this only the control that raised
the event will hear the event. Is there any way to globally raise an event
that all controls could listen too?
Thanks
Phil
Phil Guest
-
RLJ #3
Re: Global Events that all instances of a control handles
On 2006-09-11 02:03:52 -0500, "Phil" <lynch_15@hotmail.com> said:
In the user control> I have a user control (called MyControl that inherits from
> CompositeControl). This control will raise an event when the user
> changes the color of the control. (MyControl.ColorChange). Inside the
> code for MyControl, I also listen and handle the event (ColorChange). -
> This actually implements the change in color. This works OK for the
> control that raised the event.
>
> However, in the aspx form, I have 5 instances of the same user control
> (MyControl). When one of the controls change color (based on user
> input) I would like to have each instance of the MyControl listen for
> the event and handle the ChangeColor event. When I try this only the
> control that raised the event will hear the event. Is there any way to
> globally raise an event that all controls could listen too?
>
> Thanks
>
> Phil
>
* Define a Delegate
* Define an event based on the delegate
* Fire the event
In the "listener" controls
* subscribe to the event
* write an event handler
* "wire" the event handler to the delegate
/*************** Event Publisher ****************/
public PublisherClass { // the class that changed it's color
pubic delegate void myDelegate(string newColor);
public event myDelegate myEvent;
// "wire" this method to the OnChange property of your Select listbox.
private void OnColorChange(string theNewColor) {
this.myEvent();
}
}
/*********** meanwhile, in the listener contols' code ***********/
public ListenerClass {
PublisherClass myPublisher = new PublisherClass();
override protected void OnInit (EventArgs e) {
myPublisher.myEvent += myPublisher.myDelegate(ChangeMyColor);
}
public void ChangeMyColor (string newColor) {
// change the color to newColor
}
}
/************ Caveat **************/
If you want every control to listen to every other control's
ChangeColor event then I'm not sure
how to neatly implement that. I guess every control will be both a
publisher and subscriber - sounds cool, if it works - Either every
control defines it's own event and all controls subscribe to all other
control's events.. OR .. here's something wacky: think it *could* go
like this (WARNING: wild-ass guess follows):
* Define the delegate and event at the namespace level (i.e. at the
container page level?)
* Each control will have an OnChange handler for what I assume is a
drop-down select list of colors
* In that OnChange handler of every control, call the event
* in OnInit() of every control set "this.myEvent +=
this.myDelegate(ChangeMyColor)" (not too sure that "this" will cut it)
* so the drop-down list event handler fires the event and a separate
method (wired to the delegate) does the actual work
***** would this cause an infinite loop?
RLJ Guest
-
Phil #4
Re: Global Events that all instances of a control handles
Thanks for the response. I managed a workaround, but your suggestions is
much neater. Will try to implement it this way!
"RLJ" <robert@joneshouse.com> wrote in message
news:2006100101400043658-robert@joneshousecom...> On 2006-09-11 02:03:52 -0500, "Phil" <lynch_15@hotmail.com> said:
>> In the user control>> I have a user control (called MyControl that inherits from
>> CompositeControl). This control will raise an event when the user
>> changes the color of the control. (MyControl.ColorChange). Inside the
>> code for MyControl, I also listen and handle the event (ColorChange). -
>> This actually implements the change in color. This works OK for the
>> control that raised the event.
>>
>> However, in the aspx form, I have 5 instances of the same user control
>> (MyControl). When one of the controls change color (based on user input)
>> I would like to have each instance of the MyControl listen for the event
>> and handle the ChangeColor event. When I try this only the control that
>> raised the event will hear the event. Is there any way to globally raise
>> an event that all controls could listen too?
>>
>> Thanks
>>
>> Phil
>>
> * Define a Delegate
> * Define an event based on the delegate
> * Fire the event
>
> In the "listener" controls
> * subscribe to the event
> * write an event handler
> * "wire" the event handler to the delegate
>
> /*************** Event Publisher ****************/
> public PublisherClass { // the class that changed it's color
> pubic delegate void myDelegate(string newColor);
> public event myDelegate myEvent;
>
> // "wire" this method to the OnChange property of your Select
> listbox.
> private void OnColorChange(string theNewColor) {
> this.myEvent();
> }
> }
>
>
> /*********** meanwhile, in the listener contols' code ***********/
> public ListenerClass {
> PublisherClass myPublisher = new PublisherClass();
>
> override protected void OnInit (EventArgs e) {
> myPublisher.myEvent += myPublisher.myDelegate(ChangeMyColor);
> }
>
> public void ChangeMyColor (string newColor) {
> // change the color to newColor
> }
> }
>
> /************ Caveat **************/
> If you want every control to listen to every other control's ChangeColor
> event then I'm not sure
> how to neatly implement that. I guess every control will be both a
> publisher and subscriber - sounds cool, if it works - Either every control
> defines it's own event and all controls subscribe to all other control's
> events.. OR .. here's something wacky: think it *could* go like this
> (WARNING: wild-ass guess follows):
> * Define the delegate and event at the namespace level (i.e. at the
> container page level?)
> * Each control will have an OnChange handler for what I assume is a
> drop-down select list of colors
> * In that OnChange handler of every control, call the event
> * in OnInit() of every control set "this.myEvent +=
> this.myDelegate(ChangeMyColor)" (not too sure that "this" will cut it)
> * so the drop-down list event handler fires the event and a separate
> method (wired to the delegate) does the actual work
> ***** would this cause an infinite loop?
>
>
Phil Guest



Reply With Quote

