Serialize CommandEventHandler to ViewState?

Discussion in 'ASP .Net' started by DC, Apr 14, 2008.

  1. DC

    DC Guest

    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
     
    DC, Apr 14, 2008
    #1
    1. Advertising

  2. DC

    bruce barker Guest

    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
     
    bruce barker, Apr 15, 2008
    #2
    1. Advertising

  3. DC

    DC Guest

    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
     
    DC, Apr 15, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Craig Buchanan

    serialize class to the viewstate

    Craig Buchanan, Jan 27, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,181
  2. Gordz
    Replies:
    3
    Views:
    3,940
    John Oakes
    Jun 7, 2004
  3. Ben Amada

    Can viewstate serialize this class?

    Ben Amada, Oct 16, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    13,195
    john_teague
    Oct 30, 2005
  4. Fabrice
    Replies:
    7
    Views:
    429
    Fabrice
    Jun 27, 2009
  5. haile
    Replies:
    1
    Views:
    461
    haile
    Nov 24, 2004
Loading...

Share This Page