How can I set ID of nested custom control myself?

Discussion in 'ASP .Net Building Controls' started by Ken Dopierala Jr., May 10, 2005.

  1. Hi,

    In VS.Net in Design Mode when I add a bunch of the same custom control to my
    page VS.Net assigns unique IDs for the parent control (i.e. MyCalendar) but
    seems to lose track and assign the same IDs to child controls causing it to
    say that more than one control on the page is named the same. For example:

    <cc:MyCalendar id="MyCalendar1" ...>
    <MyWeek id="MyWeek1" ...>
    </MyWeek>
    <MyWeek id="MyWeek2" ...>
    </MyWeek>
    <MyWeek id="MyWeek3" ...>
    </MyWeek>
    </cc:MyCalendar>

    <cc:MyCalendar id="MyCalendar2" ...>
    <MyWeek id="MyWeek4" ...>
    </MyWeek>
    <MyWeek id="MyWeek5" ...>
    </MyWeek>
    <MyWeek id="MyWeek6" ...>
    </MyWeek>
    </cc:MyCalendar>

    <cc:MyCalendar id="MyCalendar3" ...>
    <MyWeek id="MyWeek2" ...>
    </MyWeek>
    <MyWeek id="MyWeek3" ...>
    </MyWeek>
    <MyWeek id="MyWeek7" ...>
    </MyWeek>
    </cc:MyCalendar>

    In the above all parent controls are unique but for some reason when the 3rd
    MyCalendar control is placed on the page and then MyWeeks are added through
    the Property Window via a collection dialog the MyWeek IDs suddenly start to
    repeat. I have tried it both with INamingContainer implemented and without.
    Is there a way I can programatically set the ID of the MyWeek child controls
    before VS.Net assigns one? If so, what event? I can't seem to find a place
    to break to find out where this is happening. After it happens it is too
    late because I do not want to force control of these IDs, so I won't know if
    the ID is VS.Net created or developer assigned after the initial creation.
    My goal is to always have a unique ID for every child control added and I
    can do that if I know where capture where the ID is first assigned.

    I'm coding everything in VB.Net but feel free to respond in C# or whatever
    you want. Thanks! Ken.

    P.S. My next step once this is solved is creating a custom UITypeEditor
    instead of relying on the default collection interface in the properties
    window. If there is a way I can pass in the ID of the parent
    ("MyCalendar3"), which VS.Net is always making unique, then I can prefix
    that to the child there and guarantee uniqueness. Can I pass that in? If
    so, how do I do that? Then I won't even need an answer to my main post.
    Thanks!
    Ken Dopierala Jr., May 10, 2005
    #1
    1. Advertising

  2. Hi,

    I did a quick test and using a custom UITypeEditor solves the problem. I'm
    still interested in knowing why the VS.Net collection editor starts reusing
    IDs. If I just keep creating control after control it seems to do fine, but
    if I stop and do anything like switch to the HTML view and then back to the
    Design view it starts repeating. Ken.

    "Ken Dopierala Jr." <> wrote in message
    news:...
    > Hi,
    >
    > In VS.Net in Design Mode when I add a bunch of the same custom control to

    my
    > page VS.Net assigns unique IDs for the parent control (i.e. MyCalendar)

    but
    > seems to lose track and assign the same IDs to child controls causing it

    to
    > say that more than one control on the page is named the same. For

    example:
    >
    > <cc:MyCalendar id="MyCalendar1" ...>
    > <MyWeek id="MyWeek1" ...>
    > </MyWeek>
    > <MyWeek id="MyWeek2" ...>
    > </MyWeek>
    > <MyWeek id="MyWeek3" ...>
    > </MyWeek>
    > </cc:MyCalendar>
    >
    > <cc:MyCalendar id="MyCalendar2" ...>
    > <MyWeek id="MyWeek4" ...>
    > </MyWeek>
    > <MyWeek id="MyWeek5" ...>
    > </MyWeek>
    > <MyWeek id="MyWeek6" ...>
    > </MyWeek>
    > </cc:MyCalendar>
    >
    > <cc:MyCalendar id="MyCalendar3" ...>
    > <MyWeek id="MyWeek2" ...>
    > </MyWeek>
    > <MyWeek id="MyWeek3" ...>
    > </MyWeek>
    > <MyWeek id="MyWeek7" ...>
    > </MyWeek>
    > </cc:MyCalendar>
    >
    > In the above all parent controls are unique but for some reason when the

    3rd
    > MyCalendar control is placed on the page and then MyWeeks are added

    through
    > the Property Window via a collection dialog the MyWeek IDs suddenly start

    to
    > repeat. I have tried it both with INamingContainer implemented and

    without.
    > Is there a way I can programatically set the ID of the MyWeek child

    controls
    > before VS.Net assigns one? If so, what event? I can't seem to find a

    place
    > to break to find out where this is happening. After it happens it is too
    > late because I do not want to force control of these IDs, so I won't know

    if
    > the ID is VS.Net created or developer assigned after the initial creation.
    > My goal is to always have a unique ID for every child control added and I
    > can do that if I know where capture where the ID is first assigned.
    >
    > I'm coding everything in VB.Net but feel free to respond in C# or whatever
    > you want. Thanks! Ken.
    >
    > P.S. My next step once this is solved is creating a custom UITypeEditor
    > instead of relying on the default collection interface in the properties
    > window. If there is a way I can pass in the ID of the parent
    > ("MyCalendar3"), which VS.Net is always making unique, then I can prefix
    > that to the child there and guarantee uniqueness. Can I pass that in? If
    > so, how do I do that? Then I won't even need an answer to my main post.
    > Thanks!
    >
    >
    Ken Dopierala Jr., May 10, 2005
    #2
    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. Victor Garcia Aprea [MVP]

    Re: Howto catch HttpRequestValidationException myself

    Victor Garcia Aprea [MVP], Jul 12, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    508
    Victor Garcia Aprea [MVP]
    Jul 12, 2003
  2. John Saunders
    Replies:
    0
    Views:
    428
    John Saunders
    Jul 23, 2003
  3. Alan Silver
    Replies:
    3
    Views:
    430
    Alan Silver
    Aug 9, 2005
  4. Matt Sokol
    Replies:
    2
    Views:
    375
    Theo Tillotson
    Aug 7, 2003
  5. Replies:
    0
    Views:
    178
Loading...

Share This Page