【发布时间】:2015-06-16 14:51:02
【问题描述】:
1) 我在代码隐藏中创建了一个面板,并将其 ID 指定为“Panel123”。面板稍后在 html 页面上呈现时接收其 html ID。 html 中的此 ID 看起来像“ctl00_ctl00_bla_bla_bla_Panel123”。
2) 我在代码隐藏中创建并注册了一个 javascript 块,它通过其 ID 引用面板。因此,在代码隐藏中,我需要检索面板的未来 html ID 并将此 ID 嵌入到脚本中。
我尝试过 ClientID、UniqueID、ID,但所有这些服务器端属性只给出了面板 id 的结尾部分,而不是 bla_bla_bla 的全部内容。
我也尝试将字符串“”放入脚本文本中,但随后在 html 中呈现如下(我故意添加空格以防止替换符号):' < % =Panel123.ClientID%>'。因此,如您所见,脚本无法将其识别为有效的 html ID。
如何在代码隐藏中获取整个 html id?
代码隐藏
Panel123 = new Panel();
Panel123.ID = "Panel123";
...
LinkButton123.OnClientClick = "function123(this,'<%=Panel123.ClientID%>'); return false;";
【问题讨论】:
标签: html asp.net controls code-behind identifier