Page 104
You must initialize your child controls before you add them to the Controls collection of your custom
control, because if you initialize them after you add them to the Controls collection, these initialized
property values will be saved to view state. This will unnecessarily increase the size of your custom controlâs
view state.
I need more detail explanation about the difference between :
paymentMethodList = new DropDownList();
paymentMethodList.Width = Unit.Percentage(100);
paymentMethodList.Items.Add(new ListItem(âVisaâ, âVisaâ));
paymentMethodList.Items.Add(new ListItem(âMasterCardâ, âMasterCardâ));
paymentMethodList.ID = âPaymentMethodListâ;
container.Controls.Add(paymentMethodList);
with
DropDownList paymentMethodList;
container.Controls.Add(paymentMethodList);
paymentMethodList = new DropDownList();
paymentMethodList.Width = Unit.Percentage(100);
paymentMethodList.Items.Add(new ListItem(âVisaâ, âVisaâ));
paymentMethodList.Items.Add(new ListItem(âMasterCardâ, âMasterCardâ));
paymentMethodList.ID = âPaymentMethodListâ;
Can Everybody explain more detail about why before initialization and after initialization can affect ViewState size!
Thank You Very Much
|