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$ PlaceHolde rQuestionT ype
ctl00$ContentPlaceHolder1$ PlaceHolde rQuestions
ctl00$ContentPlaceHolder1$ phControlC ontainer
ctl00$ContentPlaceHolder1$ litStoredA nswer
ctl00$ContentPlaceHolder1$ litStoredQ uestionTyp e
ctl00$ContentPlaceHolder1$ litStoredC ontrolID
The PlaceHolder control PlaceHolderQuestionType has been created manually and is there at development time.
ctl00$ContentPlaceHolder1$ PlaceHolde rQuestions and ctl00$ContentPlaceHolder1$ phControlC ontainer 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
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$
ctl00$ContentPlaceHolder1$
ctl00$ContentPlaceHolder1$
ctl00$ContentPlaceHolder1$
ctl00$ContentPlaceHolder1$
ctl00$ContentPlaceHolder1$
The PlaceHolder control PlaceHolderQuestionType has been created manually and is there at development time.
ctl00$ContentPlaceHolder1$
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");
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Have you tried .FindControl("ContentPlaceHolder1_PlaceHolderQuestions" ... ?
ASKER