Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > How can I set ID of nested custom control myself?

Reply
Thread Tools

How can I set ID of nested custom control myself?

 
 
Ken Dopierala Jr.
Guest
Posts: n/a
 
      05-10-2005
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!


 
Reply With Quote
 
 
 
 
Ken Dopierala Jr.
Guest
Posts: n/a
 
      05-10-2005
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!
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Custom control within a custom control J R M ASP .Net 2 06-01-2006 06:04 PM
How can a custom control set the value of a control on the parent page? Alan Silver ASP .Net 3 08-09-2005 10:57 AM
Capturing event from other custom control within another custom control Jonah Olsson ASP .Net 1 04-05-2005 01:39 PM
ControlDesigner not invoked on custom control when control is rendered within another custom control Matt Sokol ASP .Net Building Controls 2 08-07-2003 07:13 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57