Custom Controls- Controls Collection-FindControl method

Discussion in 'ASP .Net Web Controls' started by Sundararajan, Mar 8, 2005.

  1. Sundararajan

    Sundararajan Guest

    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.
    --
    S.Sundararajan
     
    Sundararajan, Mar 8, 2005
    #1
    1. Advertising

  2. Sundararajan

    quaester Guest

    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.

    "Sundararajan" wrote:

    > 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.
    > --
    > S.Sundararajan
     
    quaester, Mar 9, 2005
    #2
    1. Advertising

  3. Sundararajan

    Sundararajan Guest

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

    "quaester" wrote:

    > 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.
    >
    > "Sundararajan" wrote:
    >
    > > 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.
    > > --
    > > S.Sundararajan
     
    Sundararajan, Mar 10, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ani

    FindControl method doesn't work

    ani, Nov 5, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    380
  2. Karen
    Replies:
    2
    Views:
    1,133
    Karen
    May 11, 2004
  3. Øyvind Isaksen
    Replies:
    1
    Views:
    1,012
    Øyvind Isaksen
    May 18, 2007
  4. Terry Holland
    Replies:
    9
    Views:
    228
    Steven Cheng[MSFT]
    Oct 28, 2005
  5. Donald Simpson

    Web Custom Control & Custom Collection problem

    Donald Simpson, Jul 11, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    139
    Donald Simpson
    Jul 11, 2003
Loading...

Share This Page