Page Lifecycle - Using FindControl to reference a control created programatically during page load

Posted by Jay Wilde on Stack Overflow See other posts from Stack Overflow or by Jay Wilde
Published on 2008-10-10T09:04:46Z Indexed on 2010/04/19 6:03 UTC
Read the original article Hit count: 358

Filed under:
|

Hi,

I'm creating some text boxes on my form programatically which I need to reference later using FindControl.

I've put the FindControl instruction in the page load method after the code which creates them but get an error:

"Object reference not set to an instance of an object."

I assume this is because the textbox controls are not created until later in the lifecycle and therefore cannot be referenced from within Page_Load.

Can someone advise where in my code-behind I would need to place the FindControl instruction so that it can find these programatically created text boxes?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about c#