Why Server Control ID is changed?
-
Can any one let me know how the server control ID is prefixed with "_ctl0_". Any settings are required in asp.net? I am curious about this, as i found this to be useful and planning to implement in my application Thanks in Advance :)
-
Can any one let me know how the server control ID is prefixed with "_ctl0_". Any settings are required in asp.net? I am curious about this, as i found this to be useful and planning to implement in my application Thanks in Advance :)
-
Thanks for the reply I accept this, but i found this being changed for a textbox or asp:label or asp validators. It should be noted that, these are not implemented with any datagrid or related controls. Thanks in advance :)
-
Thanks for the reply I accept this, but i found this being changed for a textbox or asp:label or asp validators. It should be noted that, these are not implemented with any datagrid or related controls. Thanks in advance :)
As Thea's reply mentioned, in order to ensure that ids are unique to a page, any object that contains controls will normally implement the
[INamingContainer](http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebUIINamingContainerClassTopic.asp)[[^](http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebUIINamingContainerClassTopic.asp "New Window")]
interface, which will add a prefix [itsClientId
] to the id of all controls that it contains. This behavior is not limited to a datagrid or "related controls" [Thea used them for illustration purposes], any container hosting your controls has the potential to act as a naming container. Also, if you do not assign a specific id to the control, ASP.NET will create an id for it, with the naming scheme of "_ctl0", "_ctl1", etc. What it sounds like to me is that the controls you're asking about are being hosted in a container that did not have its id set. If you're looking to reference the id a control for client script, I'd suggest taking a peek at the[ClientID](http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebUIControlClassClientIDTopic.asp)[[^](http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebUIControlClassClientIDTopic.asp "New Window")]
property. This will resolve the id that ASP.NET assigns to the control when being rendered. Be aware, though, that if you're adding controls at runtime, theClientID
property will not be accurate until that control and all of its containers have been added to the page. Hope that helps a bit. :) --Jesse