By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,813 Members | 1,253 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,813 IT Pros & Developers. It's quick & easy.

Dynamic controls - losing viewstate after button_click event

P: n/a
I am loading my controls dynamically into my page. When I click on a
button on one of those user controls then page reloads and I need to reload
the page based on what has happened in the button click. Problem is that the
button click is the last thing to fire so I need to reload the page a second
time to update the controls based on the logic in the button click. The
second time around the page loses its viewstate which stores previously
entered data in some text boxes.

Events :

Page_Load - RenderPage()

Button is clicked.

Page_Load - RenderPage()

Button_Click event fires changing some data.

// Need to reload page based on logic changes in Button_Click

Option 1 : Server.Transfer ("Default.aspx") - This reloads the page
correctly but loses the viewstate

Option 2 : Server.Transfer ("Default.aspx",true) - This reloads the page
correctly but continually fires the button click event

Option 3 : Call RenderPage() from Button_Click- This works but user control
events are lost due to the RenderPage method being called after the
Page_Load event.

Does anyone have any ideas on how this is supposed to be done in ASP.Net?
(I'm using C#) All I want is for the viewstate to be kept between page calls
and the events to work. However, any possible solutions seem to come have
their own problems. What would be the recommended way in this case?
Feb 21 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.