Administrator

Administrator

  • Tech Writer
  • 2.2k
  • 1.5m

Dynamic add UserControl problem

Mar 27 2003 4:18 PM
Hi all! I have a page which by default shows one instance of a UserControl. I also have a Button that has the following codebehind: int iCount = (int)Session["Count"]; iCount++; Session["Count"] = iCount; Control oControl = LoadControl("EmpRecord.ascx"); oControl.ID = "oEmpRecord" + iCount.ToString(); oDivRecords.Controls.Add(oControl); oControl = null; (note that Session["Count"] is set to 1 in Page_Load if NOT postback.) Ok, so I click the button and a new instance of the UserControl shows up at the screen!! Hurray! It works! But wait! I try again, and nothing happens. The page reloads, but nothing happens. Still just 2 UserControls there. WHAT IS WRONG??? It's driving me crazy!! Thanks.

Answers (3)