You should have the code that programatically adds controls in the Page_Init method instead of the Page_Load method. This is because viewstate is loaded between init and load..