This really should be much easier, so I must be missing something obvious. I have a C# ASP.NET page that is AJAX enabled. I also have an ASP.NET panel that is initially empty but I create a couple of drop-down lists and add them in the code behind. This part works just fine. However, when the page does a postback, the controls"disappear" and I can't find them at all. Note that the panel itself is not in an AJAX update panel, I am only mentioning it because I think it might be a viewstate problem.
This code works just fine:
DropDownList newList = new DropDownList();
newList.ID = string.Format("lst{0}", opt.OptionName.ToString());
foreach (SaleItemOptions myOpt in opt.OptionsInList)
{
newList.Items.Add(myOpt.OptionName);
}
this.pnlOptions.Controls.Add(newList);
But this code always returns NULL
DropDownList myList = (DropDownList)this.pnlOptions.FindControl("lstSize");
I've verified that the control name exists in the form and I've also used variations like the ControlID, ID, etc.
Also, there is one mitigating factor in all of this. I am using the GCheckout API (Google Checkout for ASP.NET) to create the postback. That really shouldn't be an issue, but thought I'd mention it