[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.buildingcontrols

RE: When does ClientID takeon the NamingContainer prefix

Nathaniel Greene

1/24/2007 4:56:00 PM

If you use the ClientID before the control has been added , since strings are
immutable so a copy is made, any where you used the ClientID it will be old
and will not be updated. Unless you can provide code that says this, from
your description of it, this sounds like a by design issue.

This is why it is best to get everybody added to the hierarchy early on so
that there is no changing requied. And should any custom rendering or id
setting be done it be done as late as possible to ensure that anybody that
accidentally did get left behind got caught up.

"Iain" wrote:

>
>
> "Iain" wrote:
>
> > I've a complicated custom control which has been running fine for a year or
> > so. Just recently I've made a change which has stopped it working. But why?
> >
>
> Well, I've discovered the problem and regard it as a bug.
>
> I had a Debug.WriteLine in my code which printed the value of the ClientID.
> This debug line is called BEFORE the container is added to the controls
> collection (and hence before it gets it's own ID).
>
> So it would appear that if you access ClientID before the container is added
> to the control tree, the value is fixed at that. If you later add this
> control to a control collection, the new hierarchy is not reflected in the
> ClientID.
>
> Needless to say I did not expect this. I would have expected the ClientID
> to be updated if the environment which the control lived in (ie it was
> parented or reparented) was changed.
>
> Of course, the whole thing *still* doesn't work, but that's another story!
>
> Moral of the story is - if things don't work take out your debugging code ..
>
> Oh if anyone from MS reads this, could you comment on if this should be a
> bug or not and address it in future releases?
>
> Thanks to all for input.
>
> Iain
3 Answers

MasterGaurav \(www.edujini-labs.com\)

1/25/2007 1:26:00 PM

0

> I would have expected the cached value to be reset if the control was
> added
> to a Naming Container.
>
> However, without seeing the MS code it's hard to know why they've chosen
> this behaviour.

This is indeed the behaviour.
You may try out a very simple thing...

Do the following in any method, say, Page_Load:

{
Label lbl = new Label();
lbl.ID = 'crazyLabel';

//Expect it to be crazyLabel
Debug.WriteLine("ClientID of Label before adding: " + lbl.ClientID);

Repeater r = new Repeater();
r.Controls.Add(lbl);

Debug.WriteLine("ClientID of Label after adding: " + lbl.ClientID);
}


--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujini...
-----------------------------------------


Iain

1/25/2007 1:55:00 PM

0



"Gaurav Vaish (MasterGaurav)" wrote:

> > I would have expected the cached value to be reset if the control was
> > added
> > to a Naming Container.
> >
> > However, without seeing the MS code it's hard to know why they've chosen
> > this behaviour.
>
> This is indeed the behaviour.
I know it.

I just don't like it!


Iain

Teemu Keiski

1/31/2007 9:34:00 PM

0

This is probably similar stuff that I've blogged and reported at Connect

http://aspadvice.com/blogs/joteke/archive/2007/01/28/Accessing-ClientID-or-UniqueID-too-early-can-cause-i...

https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?Feedbac...

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice....
http://teemu...




"Iain" <Iain@discussions.microsoft.com> wrote in message
news:09127E63-D56C-46B5-AE7E-791F3014A683@microsoft.com...
>
>
> "Gaurav Vaish (MasterGaurav)" wrote:
>
>> > I would have expected the cached value to be reset if the control was
>> > added
>> > to a Naming Container.
>> >
>> > However, without seeing the MS code it's hard to know why they've
>> > chosen
>> > this behaviour.
>>
>> This is indeed the behaviour.
> I know it.
>
> I just don't like it!
>
>
> Iain