好吧,我对动态创建的控件的I非常困惑。
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为什么有5个不同的身份证??
什么时候应该使用不同的ID模式?
(我读了MSDN文档,但和往常一样,它们并不特别有启发性。)
如果我不关心ID是什么,只想添加一个控件&将其ID提供给动态添加的AJAX扩展程序,那么应该使用哪种模式/ID组合?
发布于 2011-08-25 21:36:18
ASP.Net 4添加了clientIdMode,如果将id属性设置为“静态”,它允许强制id属性匹配服务器端id(因此更可预测)。
发布于 2011-08-25 19:51:25
使用ClientID属性。
ClientIDMode是为了支持100%设置control..or不使用的实际ID的能力。你自己选吧。基本上,它有助于编写javascript代码。
发布于 2011-08-25 20:05:19
ClientIDMode被添加到ASP.NET 4中,以便在需要时允许控制。它对于客户端库(如jQuery )特别有用。ASP.NET的神奇之处在于控件的独特性。如果您决定使用静态,请确保它们是唯一的,因为您可能会在今后遇到一些意外的运行时错误。
https://stackoverflow.com/questions/7195919
复制相似问题