store a delegate into a viewstate?

P

Pipo

Hi,

I'm trying to store a delegate into a viewstate but I get the message that
it needs to be serialized then.
So I put the attribute <Serializable> in the delegate..but this isnt
enough...

Can someone help me with this?

Many thanks,
 
P

Pipo

??you need the reason to help me??
OK!
I've made a webcustomcontrol (inherits from control)
The DataAccessLayer is provided by multiple webservices.
So I want to give the control the delegate to get the data for it.
But now if I press a button on the webcustomcontrol its loses its delegate
so it doesnt know where to retrieve the data.(and I get the error)
The first time everything is okey, cos with
'myCustomControl.InitControl'(parameters + the delegate)' I provide the
delegate I need.
So now you know the reason.
Do you now know how I can store the delegate so that after a postback I
still got it?

(for all the other data I need to store (string, integer) I already store it
in a viewstate with no problem.
So I thought I could do the same with a delegate.
I was wrong.
How can I make a delegate serializable?

thanks



Alvin Bruney said:
what is the reason for this?

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
Pipo said:
Hi,

I'm trying to store a delegate into a viewstate but I get the message that
it needs to be serialized then.
So I put the attribute <Serializable> in the delegate..but this isnt
enough...

Can someone help me with this?

Many thanks,
 
S

Steven Cheng[MSFT]

Hi Pipo,

As for the delegate serialization problem you mentioned, here are my
understandings:

I think the problem why you can't retrieve the stored delegate from the
control's VIEWSTATE when post back is because such object like delegate is
unable to be maintain(serialized) in ASP.NET web application
enviorment. As we know , the ASP.NET is request/response based, and all the
page objects and controls(on the page) only exist during the page's
serverside processing period(their lifecycle). So if you use a delegate to
reference a page class object(or another class's member fucntion) and
serilize it into VIEWSTATE or SessionState, then the next time the page is
post back, the Page class instance(and the controls on it or local
variables) are all new created ones , their methods info will be different
from the ones you persistent in the previous VIEWSTATE or SessionState.
That cause the problem, do you think so?

So I think we still need to bind the delegate via code every time in the
control 's init period rather than store in VIEWSTATE . Thanks.



Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
S

Steven Cheng[MSFT]

Hi Pipo,

Have you had a chance to view the things in my last reply. And as for the
suggestion that bind the delegate every time when the page is loaded, I
think the Page's Init event is a proper place since at that time the child
control has been created and we can call the "InitControl" method and pass
the delegate (event handler) into the sub control there. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top