Last post Apr 20, 2011 09:20 AM by Shakti Singh Tanwar
Jun 23, 2010 11:47 AM|Helmus|LINK
pthis is what my page looks like, simplified
the pnlBodyContainer is a panel that wraps arround everything in the form
the PnlFilter contains controls ( dropdowns and textboxes ) wich the user can configure to make a selection on a record set.
When the users has made a selection and reviewed it he can print out the selection by pressing "print", a postback occurs and the following things happens.
/* lots of grids are generated and placed into the pnlBodyContainer */
This places the PnlFilter on the masterpage but still inside the form, at the top of the page.
Under that BtnGoBackButton that simply preforms a postback whit no event handlers
And under that all the data the user can then print out.
The problem is that when the user preforms a postback whit the
BtnGoBackButton all the controls in the
PnlFilter are reset.
I'm pretty sure this is because of the drastic movement whit
Form.Controls.AddAt(0,PnlFilter) but i'm not sure how to solve this.
I have tried to acces the controls in every lifescycle step after the
BtnGoBackButton postback but they are all restored to there defaults
Thank you for your time
Apr 18, 2011 09:03 AM|krishnakant|LINK
But why are you add control on postback again.
onpostback if you add control again their value will be lost.
Apr 20, 2011 09:20 AM|Shakti Singh Tanwar|LINK
controls are getting reset because in asp.net page life cycle server side events like button click gets fired after page load .. and as you know value to controls are assigned in LoadViewState event just before page load happens ...now for your controls
to maintain their state the controls should be recreated before that event which is not happening in this case...so basically what's happening is that everytime you are doing a postback you are adding a new control which is obviously empty..for information
about how to work with dynamic controls please follow below links