2

I have a DataTable from a strongly-typed DataSet that has an event handler on the TableNewRow event (to initialize some date fields)

When I save this table into Session state, the event handler fires normally until the table's serialized. On subsequent requests when I retrieve the table from Session state, the event handler no longer fires.

Is this normal behavior, and I'm expected to rewire the event handlers on deserialize? If so, since there's no way to check whether the event handler has been added, what is the proper hook for doing the rewiring?

Sean Rich
  • 2,338
  • 2
  • 20
  • 15

2 Answers2

1

Depending on your serialization, you can try to set the eventhandler through OnDeserialized attribute https://stackoverflow.com/a/4172266/1236044

For Xml serialization, maybe you can try something like this :

public override void ReadXml (XmlReader reader)
{
    base.ReadXml(reader);
    NewRow+=....
}
Community
  • 1
  • 1
jbl
  • 15,179
  • 3
  • 34
  • 101
0

How do you store your session state? If it anything other than InProc, then all your objects are serialized and saved to some database. Then they are read from deserialized. This way you lose event subscriptions.

xpda
  • 15,585
  • 8
  • 51
  • 82
Vladimir Perevalov
  • 4,059
  • 18
  • 22