How to maintain ViewState of dynamically created user controls? For example, If I am creating few instances of a User control using LoadControl(...) method, then how do I make sure that the viewstate of all these controls is during postbacks?

Questions by vikramp   answers by vikramp

Showing Answers 1 - 10 of 10 Answers

sonali panda

  • Apr 14th, 2006
 

dim btn1 as new button

btn1.eableviewstate=True

  Was this answer useful?  Yes

sonali panda

  • Apr 14th, 2006
 

Sorry

 We need to use Loadviewstae and saveview state for this

  Was this answer useful?  Yes

Dave

  • May 29th, 2006
 

Wrong. ViewState of dynamic controls is maintained automatically so long as you load the control on every request and add it to the control collection.

.Net developer

  • Sep 24th, 2006
 

can u give more clarity on the answer

  Was this answer useful?  Yes

Webmatic

  • Mar 29th, 2007
 

This article has explained view state in detail...
http://msdn.microsoft.com/msdnmag/issues/03/02/cuttingedge/

  Was this answer useful?  Yes

samiksc

  • Jul 17th, 2007
 

Any control by default has viewstate enabled. So when creating a dynamic control there is no need to set the viewstate to true - that is the default.
Another important consideration is the time in life cycle when dynamic controls should be created or re-created.
Keepng in mind that the viewstate is loaded between Init() and Load() events of the page during postback, we need to create controls in the page init event. This will load the view state of the controls as expected after the init event is complete.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions