Posted By

rumremix on 09/13/12


Tagged

dynamic Net id capture


Versions (?)

how to use dynamically generated .Net element IDs on page in jquery or css


 / Published in: ASP
 

In the examples, below, Step1 is the id given to the element. If the element is set to runat="server", when it is rendered on the page, the id will change dynamically to something like ctl00$PlaceHolderMain$Step1. But the actual value may change. To make sure we capture the correct value to manipulate the element in javascript or CSS, use the technique below. Note that this code will need to live on the same page as the element, not in an external js or css file.

  1. <%--jQuery example -->
  2.  
  3. <script>
  4. $('#<%=Step1.ClientID %>').someFunction();
  5. </script>
  6.  
  7. <%--CSS example -->
  8. <style>
  9. #<%=Step1.ClientID %> {some style...}
  10. </style>

Report this snippet  

You need to login to post a comment.