cannot find the user control with it's ID

Discussion in 'ASP .Net Web Controls' started by Davids, Dec 26, 2004.

  1. Davids

    Davids Guest

    I have this simple user control having a Datalist with id="MyDataList" in my
    page but I can't find it using the Page.FindControl() method. So I set the
    trace mode on and I see it is there but since it is placed under a panel
    control which automatically has the id "ctrl02" my user control is
    "ctrl02$MyDataList"

    Why is that?!?!
    Davids, Dec 26, 2004
    #1
    1. Advertising

  2. Davids

    Edge Guest

    Davids wrote:
    > I have this simple user control having a Datalist with
    > id="MyDataList" in my page but I can't find it using the
    > Page.FindControl() method. So I set the trace mode on and I see it is
    > there but since it is placed under a panel control which
    > automatically has the id "ctrl02" my user control is
    > "ctrl02$MyDataList"
    >
    > Why is that?!?!


    Very simple: otherwise you would get a duplicate ID
    (MyDataList) when you add your control to the page twice.

    --

    Edge
    Edge, Dec 26, 2004
    #2
    1. Advertising

  3. Davids

    Davids Guest

    well I can't understand that since I choose the ID and so it would be my
    mistake?! How the heck can I find the control with Page.Findcontrol() if
    ..Net suffixes my ID with some random name??

    "Edge" <> wrote in message
    news:%...
    > Davids wrote:
    >> I have this simple user control having a Datalist with
    >> id="MyDataList" in my page but I can't find it using the
    >> Page.FindControl() method. So I set the trace mode on and I see it is
    >> there but since it is placed under a panel control which
    >> automatically has the id "ctrl02" my user control is
    >> "ctrl02$MyDataList"
    >>
    >> Why is that?!?!

    >
    > Very simple: otherwise you would get a duplicate ID
    > (MyDataList) when you add your control to the page twice.
    >
    > --
    >
    > Edge
    >
    >
    Davids, Dec 27, 2004
    #3
  4. Yeah, you won't be able to find a control within another control.

    Assuming you put a user control with an ID of MyUserControl in the page, you
    might be able to have your page's code use
    MyUserControl.FindControl("MyDataList").

    --
    Ben Strackany
    www.developmentnow.com


    "Davids" <> wrote in message
    news:cqppaq$oec$...
    > well I can't understand that since I choose the ID and so it would be my
    > mistake?! How the heck can I find the control with Page.Findcontrol() if
    > .Net suffixes my ID with some random name??
    >
    > "Edge" <> wrote in message
    > news:%...
    > > Davids wrote:
    > >> I have this simple user control having a Datalist with
    > >> id="MyDataList" in my page but I can't find it using the
    > >> Page.FindControl() method. So I set the trace mode on and I see it is
    > >> there but since it is placed under a panel control which
    > >> automatically has the id "ctrl02" my user control is
    > >> "ctrl02$MyDataList"
    > >>
    > >> Why is that?!?!

    > >
    > > Very simple: otherwise you would get a duplicate ID
    > > (MyDataList) when you add your control to the page twice.
    > >
    > > --
    > >
    > > Edge
    > >
    > >

    >
    >
    Ben Strackany, Dec 27, 2004
    #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. Jacob Avlund

    Cannot find type of user control?

    Jacob Avlund, Sep 23, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    532
    Jacob Avlund
    Sep 23, 2004
  2. Daves
    Replies:
    5
    Views:
    4,276
    topherzee
    Sep 10, 2008
  3. Samy
    Replies:
    4
    Views:
    573
  4. Samy
    Replies:
    2
    Views:
    2,005
  5. =?Utf-8?B?RQ==?=
    Replies:
    0
    Views:
    436
    =?Utf-8?B?RQ==?=
    Sep 11, 2007
Loading...

Share This Page