Dynamic controls disappear after postback

asp.netdynamicpageloadpostbackuser-controls

I have a whole lot of controls to be created dynamically. Where is the best place to run the code for that?

I have been running the CreateControls function (to create all controls) at Page_Load.

Now the problem is, when I uncheck/uncheck one particular dynamic checkbox control (autopostback = true), the checkbox is always set to "true" because the CreateControls function runs again at Page_Load on postback.

If I put the CreateControls function within the (!IsPostBack) of Page_Load, when I click on the dynamic checkbox control, all controls disappear.

I have been looking at this for days, any ideas appreciated!

EDIT: The CreateControls function binds all the controls to a Panel.

Best Answer

Try calling your CreateControls method in Page_Init method instead of Page_Load... the Init event fires before the form values are bound to the controls, so your default values will be overwritten with the correct data.

Related Topic