如何确定ASP.NET的生成的ID从codebehind的? [英] How to determine ASP.NET's generated ID's from codebehind?
问题描述
在ASP.NET中,当你给一个标签的ID它生成一个独特的HTML ID为基于控制层次结构,即该元素。
In ASP.NET, when you give a tag an ID it generates a unique HTML id for the element based on the control hierachy, ie.
<asp:Panel ID="test" runat="server">
...
</asp:Panel>
<!-- Becomes... -->
<div id="plc_lt_zoneContent_PagePlaceholder_PagePlaceholder_lt_test_test">
...
</div>
有没有确定在codebehind文件中生成的ID的一些方法?我需要生成一个使用该ID一些JavaScript。
Is there some way of determining the generated id in the codebehind file? I need to generate some Javascript that uses the id.
推荐答案
在JavaScript这样做:
Do this in javascript:
<script type="text/javascript">
var theID = '<%= test.ClientID %>';
// theID contains your ID
</script>
更新:我注意到低于注释客户端Id
没有工作。这是客户端ID
(区分大小写)。这里的文件引用的ClientID:
Update: I noticed a comment below that ClientId
didn't work. It's ClientID
(case sensitive). Here's the documentation reference to ClientID:
<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.control.clientid%28VS.71%29.aspx\">http://msdn.microsoft.com/en-us/library/system.web.ui.control.clientid(VS.71).aspx
这篇关于如何确定ASP.NET的生成的ID从codebehind的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!