title: asp.NET: How to access repeater generated elements?
body: <p>i have a repeater than creates a table:</p>
  
  <pre><code>&lt;itemtemplate&gt;
     &lt;tr id="theTableRow" runat="server"&gt;
        &lt;td&gt;
           &lt;asp:LinkButton runat="server"
              OnClientClick="todo"
              Text="Do Something" /&gt;
        &lt;/td&gt;
     &lt;/tr&gt;
  &lt;/itemtemplate&gt;
  </code></pre>
  
  <p><strong>Note:</strong> the <code>OnClientClick="todo"</code> line. </p>
  
  <p>In the final rendered code, i want the <em>todo</em> to contain a call to a javascript function, passing:</p>
  
  <ul>
  <li>the ID of the generated table row, and </li>
  <li>the Eval of a property of the currently bound object</li>
  </ul>
  
  <p>And now for some <em>pseudo-code</em>:</p>
  
  <p><strong>Pseudocode 1:</strong></p>
  
  <p>OnClientClick="DoSomething(theTableRow, CromulentGuid); return false;"</p>
  
  <p><strong>Pseudocode 2</strong></p>
  
  <p>OnClientClick="javascript:DoSomething(theTableRow, CromulentGuid); return false;"</p>
  
  <p><strong>Pseudocode 3</strong></p>
  
  <p>OnClientClick="javascript:DoSomething(theTableRow, &lt;%# Eval("CromulentGuid") %>); return false;"</p>
  
  <p><strong>Pseudocode 4</strong></p>
  
  <p>OnClientClick="javascript:DoSomething(&lt;%= theTableRow %>, &lt;%# Eval("CromulentGuid") %>); return false;"</p>
  
  <p><strong>Pseudocode 5</strong></p>
  
  <p>OnClientClick='javascript:DoSomething(&lt;%= Eval(theTableRow) %>, &lt;%# Eval("CromulentGuid") %>); return false;'</p>
  
  <p>Whatever the ASP.NET code used, i want the rendered HTML to be:</p>
  
  <pre><code>&lt;tr id="ctl00__itemRepeater_ctl01_theTableRow"&gt;
     &lt;td&gt;
        &lt;a 
              onclick="DoSomething('ctl00__itemRepeater_ctl01_theTableRow', '19a149db-5675-4eee-835d-3d78372ca6f9'); return false;"
              href="javascript:__doPostBack('ctl00$itemRepeater$ctl01$ctl04','')"&gt;
           Do Something
        &lt;/a&gt;
     &lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>i would also be okay with:</p>
  
  <pre><code>&lt;tr id="ctl00__itemRepeater_ctl01_theTableRow"&gt;
     &lt;td&gt;
        &lt;a 
              onclick='DoSomething(&amp;quot;ctl00__itemRepeater_ctl01_theTableRow&amp;quot;, &amp;quot;19a149db-5675-4eee-835d-3d78372ca6f9&amp;quot;); return false;'
              href="javascript:__doPostBack('ctl00$itemRepeater$ctl01$ctl04','')"&gt;
           Do Something
        &lt;/a&gt;
     &lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p><strong>Note:</strong> i'm okay with the 2nd form since i know it is functionally identical, and ASP.NET code cannot generate the former, even if the latter is less readable.</p>
  
  <hr>
  
  <p>Related questions:</p>
  
  <p><a href="https://stackoverflow.com/questions/474584/asp-net-how-to-access-repeater-generated-elements-from-javascript">ASP.NET: How to access repeater generated elements from javascript?</a></p>