Okay, I'm pretty confused about the IDs of dynamically created controls.
Public Class TestClass
Inherits Panel
Implements INamingContainer
Function TestClassInit() Handles Me.Init
Dim pnlMainPanel As New Panel
Me.Controls.Add(pnlMainPanel)
Dim pnlTest1 As New Panel
pnlMainPanel.Controls.Add(pnlTest1)
pnlTest1.ClientIDMode = UI.ClientIDMode.Inherit ' DEFAULT
'pnlTest1.ID = "ctl01"
'pnlTest1.UniqueID = "ctl00$MainPanel$ctl01"
'pnlTest1.ClientID = "MainPanel_ctl01"
'pnlTest1.UniqueClientID = "ctl00_MainPanel_ctl01"
'pnlTest1.StaticClientID = ""
pnlTest1.ClientIDMode = UI.ClientIDMode.Predictable
'pnlTest1.ClientID = "MainPanel_ctl01" (no change)
pnlTest1.ClientIDMode = UI.ClientIDMode.AutoID
'pnlTest1.ClientID = "ctl00_MainPanel_ctl01"
pnlTest1.ClientIDMode = UI.ClientIDMode.Static
'pnlTest1.ClientID = ""
End Function
End Class
Why the 5 different IDs??
When should you use the different ID modes?
(I read the MSDN docs, but they were, as usual, not particularly illuminating.)
If I don't care what the ID is, and just want to add a control & give its ID to a dynamically added AJAX extender, which mode/ID combo should I use?
ASP.Net 4 adds clientIdMode which allows you to force the id attribute to match the serverside id (and thus be more predictable) if you set it to "static".
Use the ClientID property.
ClientIDMode is there to support the ability to 100% set the actual ID used by the control..or not. Your choice. Basically it aids in writing javascript code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With