Viewstate access

A

Amr Al Jarhi

I have a webform, with a statically declared usercontrol in it...
the usercontrol is actually a webcontrol ( inherits from class
WebControl)
this control has some child controls created dynamically at the event:
CreateChildControls
obviously this event is fired before the viewstate is loaded, so i
cannot save or load anything from the viewstate.
the question is: how can i use the viewstate from inside the
usercontrol? Or if i cannot, what is the best practice to save and
load volatile data
between postbacks from within the usercontrol?
 
A

Ashish Kaila

Implement INamingContainer interface in your webcontrol and override
LoadViewState and SaveViewState to save the state of your control.
HTH
Ashish
 
A

amr.aljarhi

Thank you Ashish for your reply. This approach was suggested to me, but
to my specific purpose I have found that it is a little complicated. I
thought that inheriting from webcontrol would be very similar to
inheriting from usercontrol. My problem was solved by inheriting from
usercontrol instead. I guess inheriting from the webcontrol class is
not very usefull, unless I want to inherit from a specific webcontrol,
like textbox, and utilize the base functionality. But obviuosly
inheriting from the general webcontrol class does not give any
particular advantage that I am aware of over inheriting from user
control.
 

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,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top