Question

When i store a delegate (that points to a page method) in session state, retrive it after a postback and execute it the target of the delegate is the old page object and not the current one, is there anyway to change the target of the delegate so that it executes the method on the current page object ?

I have thought about using a static page method but then i don't have access to the controls on the page which defeats the object of what i am trying to do, which is update a text box.

Was it helpful?

Solution

Make your delegate take the new page as its first parameter, and when you call it pass this.

OTHER TIPS

I'm a little nervous about this. Both Jon Skeet's and Mehrdad's suggestions will work (of course), but page instances are supposed to be disposed after a request completes. This delegate could be preventing that from happening, leading to the .Net equivalent of a memory leak.

Perhaps you could use reflection and put a System.Reflection.MethodBase or System.Reflection.MethodInfo object in the session to invoke later instead.

delegateInstance.Method.Invoke(obj, arguments);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top