1

I've lost my C# Panel Controls....

the asp for my panel is

 <asp:Panel ID="pnlSett1" GroupingText="Contra Account 1" runat="server" 
            Width="400" >
 </asp:Panel>

I've set up the controls in code behind using

Label lblCompanyNumber = new Label();
lblCompanyNumber.Text = "ABCDEF";
lblCompanyNumber.ID = "CompanyNumber";
pnlSett1.Controls.Add(lblCompanyNumber);

But after the panel is populated and the user clicks on the ContraUpdate button (postback) ---

protected void btnContraUpdate_Click(object sender, EventArgs e)

        Control pnlCompanyNumber = pnlSett1.FindControl("CompanyNumber");

it can't find the control....Null value returned

Any ideas, i've tried putting the Find Control after the initial Control Add to prove the FindControl is correct and it is, but then I tried it on the PageLoad on the way back in, and that brings back Null value as well......

StuartLC
  • 104,537
  • 17
  • 209
  • 285
Adam
  • 111
  • 2
  • 14
  • Two quick checks before I answer. Is the middle code in a if(!isPostBack) {} and is it the label that you are missing? – Daniel Casserly Sep 05 '12 at 15:36
  • no the Control set up is in its own method, and the FindControl is in the contraupdate click, although I did have it as the 1st statement in the PageBuild Method, and that didn't work. And its the text I want from the label. – Adam Sep 05 '12 at 15:54
  • When in the page cycle is this code called? – Daniel Casserly Sep 05 '12 at 15:54
  • the sequence is like this - page displayed with empty panel - button click populates controls on the panel - same web page displayed with Labels in Panel - user clicks on btnContraUpdate and that is when I am trying to find my Label controls (and a chkbox!) – Adam Sep 06 '12 at 08:49

0 Answers0