Link to home
Start Free TrialLog in
Avatar of rito1
rito1

asked on

FindControl for Dynamic created Page controls

Hi All,

I am receiving the good old 'Object reference not set to an instance of an object.' error at  the moment when trying to use the FindControl within my code behind.

Here is what my Control Tree looks like when Trace is enabled:

ctl00$ContentPlaceHolder1$PlaceHolderQuestionType
   ctl00$ContentPlaceHolder1$PlaceHolderQuestions
      ctl00$ContentPlaceHolder1$phControlContainer
         ctl00$ContentPlaceHolder1$litStoredAnswer
         ctl00$ContentPlaceHolder1$litStoredQuestionType
         ctl00$ContentPlaceHolder1$litStoredControlID


The PlaceHolder control PlaceHolderQuestionType has been created manually and is there at development time.

ctl00$ContentPlaceHolder1$PlaceHolderQuestions and ctl00$ContentPlaceHolder1$phControlContainer are created dynamically within my code behind.

When trying to use the FindControl function like within my code attached I get 'Object reference not set to an instance of an object' which is referring to phControlContainer.

Can anyone see what I could be doing wrong?

Thanks,

Rit




PlaceHolder PlaceHolderQuestions = (PlaceHolder)PlaceHolderQuestionType.FindControl("PlaceHolderQuestions");

PlaceHolder phControlContainer = (PlaceHolder)PlaceHolderQuestions.FindControl("phControlContainer");

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Alfred A.
Alfred A.
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rito1
rito1

ASKER

Thanks Alfred1, I am just giving it ago.
Have you tried .FindControl("ContentPlaceHolder1_PlaceHolderQuestions" ... ?