Problem accessing control from inside other control

Discussion in 'ASP .Net Building Controls' started by Nathan Sokalski, Jan 3, 2008.

  1. I have a validator that I wrote by inheriting from BaseValidator. At certain
    points in the code, I need to access other controls on the page containing
    the validator. I have the IDs of these controls, so I use the following
    statement to access them:

    Me.Page.FindControl(ControlID)

    However, this is returning Nothing, even though the control can be accessed
    in the Load event of the Page containing the control and the validator. I
    also want to mention that the Page uses a Master Page, and the control and
    validator are declared in the Page, not the Master Page. I am not sure if
    this makes a difference or not. Can someone tell me what I am doing wrong?
    Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
    Nathan Sokalski, Jan 3, 2008
    #1
    1. Advertising

  2. Nathan Sokalski

    Dina Guest

    On Jan 3, 9:19 am, "Nathan Sokalski" <> wrote:
    > I have a validator that I wrote by inheriting from BaseValidator. At certain
    > points in the code, I need to access other controls on the page containing
    > the validator. I have the IDs of these controls, so I use the following
    > statement to access them:
    >
    > Me.Page.FindControl(ControlID)
    >
    > However, this is returning Nothing, even though the control can be accessed
    > in the Load event of the Page containing the control and the validator. I
    > also want to mention that the Page uses a Master Page, and the control and
    > validator are declared in the Page, not the Master Page. I am not sure if
    > this makes a difference or not. Can someone tell me what I am doing wrong?
    > Thanks.
    > --
    > Nathan Sokalski
    > ://www.nathansokalski.com/


    Can you please give more details on where u want to access and where u
    are already able to access the controls as in the server side or the
    client side?

    If u are able to access the controls on the server side and have
    trouble accessing them from the client side, then the solution is
    pretty simple. By default the client IDs of the server controls get
    pre-pended with specific values (I've generally observed the value
    "CT001_" or something similar). Just run the page and view the html
    source to see the client id of the controls in the client scripts. U
    can also get the client id of the controls using a property on the
    server side.

    Hope this helps

    Regards, Dina
    Dina, Jan 3, 2008
    #2
    1. Advertising

  3. As I mentioned in my original post, I am able to access the control in the
    Load event of the Page. The place where I want to and am not able to access
    it is in the EvaluateIsValid() function of my validator. In the
    EvaluateIsValid() function I am attempting to access it using the following:

    Me.Page.FindControl(ControlID)

    Because the Load event of the Page occurs before the EvaluateIsValid()
    function is called, this shows that the control does exist in the page when
    I try to access it. Is there something else I need to do when accessing the
    control from inside EvaluateIsValid()? Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Dina" <> wrote in message
    news:...
    > On Jan 3, 9:19 am, "Nathan Sokalski" <> wrote:
    >> I have a validator that I wrote by inheriting from BaseValidator. At
    >> certain
    >> points in the code, I need to access other controls on the page
    >> containing
    >> the validator. I have the IDs of these controls, so I use the following
    >> statement to access them:
    >>
    >> Me.Page.FindControl(ControlID)
    >>
    >> However, this is returning Nothing, even though the control can be
    >> accessed
    >> in the Load event of the Page containing the control and the validator. I
    >> also want to mention that the Page uses a Master Page, and the control
    >> and
    >> validator are declared in the Page, not the Master Page. I am not sure if
    >> this makes a difference or not. Can someone tell me what I am doing
    >> wrong?
    >> Thanks.
    >> --
    >> Nathan Sokalski
    >> ://www.nathansokalski.com/

    >
    > Can you please give more details on where u want to access and where u
    > are already able to access the controls as in the server side or the
    > client side?
    >
    > If u are able to access the controls on the server side and have
    > trouble accessing them from the client side, then the solution is
    > pretty simple. By default the client IDs of the server controls get
    > pre-pended with specific values (I've generally observed the value
    > "CT001_" or something similar). Just run the page and view the html
    > source to see the client id of the controls in the client scripts. U
    > can also get the client id of the controls using a property on the
    > server side.
    >
    > Hope this helps
    >
    > Regards, Dina
    Nathan Sokalski, Jan 3, 2008
    #3
  4. Nathan Sokalski

    Dina Guest

    On Jan 3, 10:42 am, "Nathan Sokalski" <> wrote:
    > As I mentioned in my original post, I am able to access the control in the
    > Load event of the Page. The place where I want to and am not able to access
    > it is in the EvaluateIsValid() function of my validator. In the
    > EvaluateIsValid() function I am attempting to access it using the following:
    >
    > Me.Page.FindControl(ControlID)
    >
    > Because the Load event of the Page occurs before the EvaluateIsValid()
    > function is called, this shows that the control does exist in the page when
    > I try to access it. Is there something else I need to do when accessing the
    > control from inside EvaluateIsValid()? Thanks.
    > --
    > Nathan Sokalski
    > ://www.nathansokalski.com/
    >
    > "Dina" <> wrote in message
    >
    > news:...
    >
    > > On Jan 3, 9:19 am, "Nathan Sokalski" <> wrote:
    > >> I have a validator that I wrote by inheriting from BaseValidator. At
    > >> certain
    > >> points in the code, I need to access other controls on the page
    > >> containing
    > >> the validator. I have the IDs of these controls, so I use the following
    > >> statement to access them:

    >
    > >> Me.Page.FindControl(ControlID)

    >
    > >> However, this is returning Nothing, even though the control can be
    > >> accessed
    > >> in the Load event of the Page containing the control and the validator. I
    > >> also want to mention that the Page uses a Master Page, and the control
    > >> and
    > >> validator are declared in the Page, not the Master Page. I am not sure if
    > >> this makes a difference or not. Can someone tell me what I am doing
    > >> wrong?
    > >> Thanks.
    > >> --
    > >> Nathan Sokalski
    > >> ://www.nathansokalski.com/

    >
    > > Can you please give more details on where u want to access and where u
    > > are already able to access the controls as in the server side or the
    > > client side?

    >
    > > If u are able to access the controls on the server side and have
    > > trouble accessing them from the client side, then the solution is
    > > pretty simple. By default the client IDs of the server controls get
    > > pre-pended with specific values (I've generally observed the value
    > > "CT001_" or something similar). Just run the page and view the html
    > > source to see the client id of the controls in the client scripts. U
    > > can also get the client id of the controls using a property on the
    > > server side.

    >
    > > Hope this helps

    >
    > > Regards, Dina


    Did u find the control's client ID by looking into the HTML source
    generated at the browser? Use that ID in the FindControl function.

    Regards, Dina
    Dina, Jan 10, 2008
    #4
    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. DC Gringo
    Replies:
    4
    Views:
    4,805
    mfreidge
    Dec 17, 2007
  2. HockeyFan
    Replies:
    1
    Views:
    987
    Masudur
    Jul 4, 2007
  3. Nathan Sokalski
    Replies:
    3
    Views:
    337
  4. Kiran More
    Replies:
    2
    Views:
    306
    Kiran More
    Nov 14, 2006
  5. Nathan Sokalski

    Problem accessing control from inside other control

    Nathan Sokalski, Jan 3, 2008, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    135
    Nathan Sokalski
    Jan 3, 2008
Loading...

Share This Page