Saturday, March 31, 2012

Subscribing to event from Template Column

I have an ascx control in the ItemTemplate of a Template Column in a
datagrid. The control (myControl) raises an event.
I'm trying to figure out how I can subscribe to the event. It can't be done
at design time because myControl is not one of the recognized controls. At
run time I would expect to use AddHandler but I can't seem to reference
myControl.
How can I subscribe to the event?
Thanks,
THi Tina,
If your control is simply a composite control that is placed declaratively
on the page at design time then you can add the event handler within the asc
x
codebehind file.
Alternatively, you can use event delegates to expose events out of your ascx
to its NamingContainer (in your case it is the DataGridItem) as I did in thi
s
example: http://www.societopia.net/Samples/D...tDelegates.aspx
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Tina" wrote:

> I have an ascx control in the ItemTemplate of a Template Column in a
> datagrid. The control (myControl) raises an event.
> I'm trying to figure out how I can subscribe to the event. It can't be do
ne
> at design time because myControl is not one of the recognized controls. A
t
> run time I would expect to use AddHandler but I can't seem to reference
> myControl.
> How can I subscribe to the event?
> Thanks,
> T
>
>
I guess I'm going to have to learn c# if for nothing other than to follow
the examples...
in VB to handle an event we ....
AddHandler myControl.TimerEvent, AddressOf me.HandleTimerEvent
.
.
Protected Sub HandleTimerEvent(byval o as Object, byval e as TimerArgs)
. code to handle event is here...
end sub
How would the AddHandler code look in the case where myControl is in
DataGrid1?
"Phillip Williams" <Phillip.Williams@.webswapp.com> wrote in message
news:0EF5A6EE-2CBF-4FDE-9B9F-148297D8E8CA@.microsoft.com...
> Hi Tina,
> If your control is simply a composite control that is placed declaratively
> on the page at design time then you can add the event handler within the
> ascx
> codebehind file.
> Alternatively, you can use event delegates to expose events out of your
> ascx
> to its NamingContainer (in your case it is the DataGridItem) as I did in
> this
> example: http://www.societopia.net/Samples/D...tDelegates.aspx
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
> "Tina" wrote:
>
Hi Tina,
For you to be able to handle an event (e.g. TimerEvent) raised by your
control it has to define a delegate method that you can use when placing tha
t
control in the DataGrid. If it does that then you can handle that event by
specifying a function for the delegate method (e.g. if your event is named
TimerEvent, you should design your control to expose a method named
OnTimerEvent)
I created here
http://www.societopia.net/Samples/D...rolsEvents.aspx a sampl
e
in VB.Net where I designed a user control (in an ascx file) that raises an
event (I called it CustomEvent1) by exposing a delegate method called
“OnCustomEvent1”. I then included that control in a TemplateColumn on t
he
DataGrid and wired the delegate function named OnCustomEvents to an event
handler within the page class codebehind.
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Tina" wrote:

> I guess I'm going to have to learn c# if for nothing other than to follow
> the examples...
> in VB to handle an event we ....
> AddHandler myControl.TimerEvent, AddressOf me.HandleTimerEvent
> ..
> ..
> Protected Sub HandleTimerEvent(byval o as Object, byval e as TimerArgs)
> .. code to handle event is here...
> end sub
> How would the AddHandler code look in the case where myControl is in
> DataGrid1?
> "Phillip Williams" <Phillip.Williams@.webswapp.com> wrote in message
> news:0EF5A6EE-2CBF-4FDE-9B9F-148297D8E8CA@.microsoft.com...
>
>

0 comments:

Post a Comment