views:

28

answers:

1

I'm using a wizard control, step 1 has a list box with a list box containing entries 1-10. Step 2 then dynamically build and displays 1 list box per entry. Each list box in step 2 contains 5 entries each. I have one more step that needs to read the list boxes from step 2 and get their values to display 3 radio buttons per choosen entry from step 2.

Currently I have 3 methods that I run populateStep1() populateStep2() populateStep3(). I run each in Page_Load.

void page_load()
{
    if(!Page.IsPostBack)
    {
      populateStep1();
    }

    populateStep2();
    populateStep3();
}

my problem is that step 3 never works the first time around. It works the second time but not the first. I believe this is because the controls in step 2 have not yet had the viewstate applied so there is nothing chosen.

Anyone want sketch out/point me to a pattern to handle working with dynamic controls that are dependent on other dynamic controls?

A: 

If you are working with Dynamically added controls then you really need to add them during the Initialization pase of the page life cycle as this will ensure View State is hydrated properly.

Since View State is hydrated before Page_Load, you are adding things too late.

Move your logic into the Page_Init method and you should be golden.

void Page_Init()
{
    if(!Page.IsPostBack)
    {
      populateStep1();
    }

    populateStep2();
    populateStep3();
}
Josh