Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Why Server Control ID is changed?

Why Server Control ID is changed?

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netsysadminquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Murugavel S
    wrote on last edited by
    #1

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

    T 1 Reply Last reply
    0
    • M Murugavel S

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

      T Offline
      T Offline
      Thea Burger
      wrote on last edited by
      #2

      Any control that implements INamingContainer, ie. Datagrid, Repeater changes the IDs of the controls within them to keep all the control ids on the page unique. The same happens with user controls. Have a look at this[^] and this[^]to see how to access these controls. HTH, :)

      M 1 Reply Last reply
      0
      • T Thea Burger

        Any control that implements INamingContainer, ie. Datagrid, Repeater changes the IDs of the controls within them to keep all the control ids on the page unique. The same happens with user controls. Have a look at this[^] and this[^]to see how to access these controls. HTH, :)

        M Offline
        M Offline
        Murugavel S
        wrote on last edited by
        #3

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

        J 1 Reply Last reply
        0
        • M Murugavel S

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

          J Offline
          J Offline
          Jesse Squire
          wrote on last edited by
          #4

          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 [its ClientId] 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, the ClientID 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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups