Serialize CommandEventHandler to ViewState?
am 14.04.2008 20:22:46 von DC
Hi,
I would like to reuse a webcontrol in several places and when a
certain action is being executed in the webcontrol, a defineable
method should run. That method of course is defined in an event in the
webcontrol:
public event CommandEventHandler MyCallBack;
Now in the hosting control I can do stuff like
myCallBack += this.MyCallbackHandler;
and that will work for that one request, but I have to specify
MyCallbackHandler at every roundtrip. Is it possible to store this
information somehow? I played around with ViewState, but I found out
that a CommandEventHandler cannot be serialized. Am I missing a design
rule?
TIA,
DC
Re: Serialize CommandEventHandler to ViewState?
am 15.04.2008 03:05:59 von DFS
object addresses can not be serialized. you could copy the browsers and
have a string method to store the callback. then on callback use
refection to call the routine.
not sure why you do not want to hookup the callback every postback? some
code has too as they are new class instances.
-- bruce (sqlwork.com)
DC wrote:
> Hi,
>
> I would like to reuse a webcontrol in several places and when a
> certain action is being executed in the webcontrol, a defineable
> method should run. That method of course is defined in an event in the
> webcontrol:
>
> public event CommandEventHandler MyCallBack;
>
> Now in the hosting control I can do stuff like
>
> myCallBack += this.MyCallbackHandler;
>
> and that will work for that one request, but I have to specify
> MyCallbackHandler at every roundtrip. Is it possible to store this
> information somehow? I played around with ViewState, but I found out
> that a CommandEventHandler cannot be serialized. Am I missing a design
> rule?
>
> TIA,
> DC
Re: Serialize CommandEventHandler to ViewState?
am 15.04.2008 09:37:20 von DC
On 15 Apr., 03:05, bruce barker wrote:
> object addresses can not be serialized. you could copy the browsers and
> have a string method to store the callback. then on callback use
> refection to call the routine.
>
> not sure why you do not want to hookup the callback every postback? some
> code has too as they are new class instances.
>
> -- bruce (sqlwork.com)
>
>
>
> DC wrote:
> > Hi,
>
> > I would like to reuse a webcontrol in several places and when a
> > certain action is being executed in the webcontrol, a defineable
> > method should run. That method of course is defined in an event in the
> > webcontrol:
>
> > public event CommandEventHandler MyCallBack;
>
> > Now in the hosting control I can do stuff like
>
> > myCallBack += this.MyCallbackHandler;
>
> > and that will work for that one request, but I have to specify
> > MyCallbackHandler at every roundtrip. Is it possible to store this
> > information somehow? I played around with ViewState, but I found out
> > that a CommandEventHandler cannot be serialized. Am I missing a design
> > rule?
>
> > TIA,
> > DC- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -
Thanks, Bruce. I thought it was more convenient to set the callback
only once but you are actually right, it is not that much effort to
wire it up on every postback.
Regards
DC