Custom Controls- Controls Collection-FindControl method

S

Sundararajan

Hi folks,

I have some 10 LinkButton controls by the name
lnkbtnPage1,lnkbtnPage2...lnkbtnPage10.
I manipulate the visibility of these controls by

for(intLoop=1; intLoop<GROUPPAGESIZE;intLoop++)
{
((LinkButton)(FindControl("lnkbtnPage"+intLoop))).Visible=false;
}

This works fine in user controls.
But i want to do the same operation in Custom controls there this
FindControl does not work and it throws the error object reference not set to
an instance of the object.

I am doing this after adding the link buttons to the Controls collection in
CreateChildControls method.

Is there any work around.
 
Q

quaester

you have to put your codes in the last few events of the control, in my case
it works when i put it in the PreRender event handler.

Reason being is that your controls classes is not loaded yet!

Take me some time to figure out though, hofully yours is the same issue.
 
S

Sundararajan

However as i am adding the controls in the CreateChildControls() method of
the control class is that possible to voverride the prerender method.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top