I have a situation where I have a form that will hold one of about twenty User Controls at any one time. Here's the code I've written so far:
private void LoadUserControl(string controlName, int property1)
{
if (CurrentUserControlName != controlName)
CurrentUserControlName = controlName;
UserControl userControl = (UserControl)LoadControl(controlName);
// Important Note: This next line is critically important. By restoring the ID value
// the ViewState of the control is restored. Without it, it isn't.
userControl.ID = CurrentUserControlName;
// Preset the properties of this control
((GeneralInfo)userControl).Pr ...
Go to the complete details ...