How to determine the generated ASP.NET identifier from code?

In ASP.NET, when you give an ID tag, it generates a unique HTML identifier for the element based on the control hierarchy, i.e.

<asp:Panel ID="test" runat="server">
    ...
</asp:Panel>
<!-- Becomes... -->
<div id="plc_lt_zoneContent_PagePlaceholder_PagePlaceholder_lt_test_test">
    ...
</div>

Is there a way to determine the generated identifier in the codebehind file? I need to generate Javascript that uses an identifier.

+3
source share
3 answers

Do it in javascript:

<script type="text/javascript">

  var theID = '<%= test.ClientID %>';
  // theID contains your ID

</script>

Update: I noticed a comment below that ClientIddidn't work. It is ClientId(case sensitive). Here's a link to the ClientID documentation:

http://msdn.microsoft.com/en-us/library/system.web.ui.control.clientid(VS.71).aspx

+10

ClientID, PreRender ( ).

ASP.NET 4 , "" , .

+1

Or use ClientIDMode = "Static" in an asp.net element

0
source

Source: https://habr.com/ru/post/1736923/


All Articles