Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine ASP.NET's generated ID's from codebehind?

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>

Is there some way of determining the generated id in the codebehind file? I need to generate some Javascript that uses the id.

like image 315
Matthew Scharley Avatar asked Aug 17 '26 06:08

Matthew Scharley


1 Answers

Do this in javascript:

<script type="text/javascript">

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

</script>

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

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

like image 154
Keltex Avatar answered Aug 19 '26 20:08

Keltex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!