HighTechTalks DotNet Forums  

RE: When does ClientID takeon the NamingContainer prefix

ASP.net Building Controls microsoft.public.dotnet.framework.aspnet.buildingcontrols


Discuss RE: When does ClientID takeon the NamingContainer prefix in the ASP.net Building Controls forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Nathaniel Greene
 
Posts: n/a

Default RE: When does ClientID takeon the NamingContainer prefix - 01-24-2007 , 11:56 AM






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:

Quote:

"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

Reply With Quote
  #2  
Old   
Gaurav Vaish \(MasterGaurav\)
 
Posts: n/a

Default Re: When does ClientID takeon the NamingContainer prefix - 01-25-2007 , 08:25 AM






Quote:
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.edujinionline.com
-----------------------------------------




Reply With Quote
  #3  
Old   
Iain
 
Posts: n/a

Default Re: When does ClientID takeon the NamingContainer prefix - 01-25-2007 , 08:55 AM





"Gaurav Vaish (MasterGaurav)" wrote:

Quote:
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


Reply With Quote
  #4  
Old   
Teemu Keiski
 
Posts: n/a

Default Re: When does ClientID takeon the NamingContainer prefix - 01-31-2007 , 04:34 PM



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

http://aspadvice.com/blogs/joteke/ar...se-issues.aspx

https://connect.microsoft.com/Visual...dbackID=254373

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net




"Iain" <Iain (AT) discussions (DOT) microsoft.com> wrote

Quote:

"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


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.