Passing variable to codebehind when using dynamic hyperlink with onserverclick
<p>Im displaying a table of rows and want to have a delete button next to each row. The table is generated using a loop. Each link contains <code>onserverclick="deleteScheduleField"</code>. What i need to be able to do is <code>onserverclick="deleteScheduleField(rowid)"</code>, but this cant be done. </p>

<p>Most guides i have seen say to use the ID field, but since these rows are dynamically i cant do this. Whenever i try to use a dynamic Id i get the following error. If i add the following to the href i get the error <code>id="&lt;%= scheduleField["id"] %&gt;"</code></p>

<blockquote>
  <p>Server tags cannot contain &lt;% ... %> constructs.</p>
</blockquote>

<p>I tried to look up a solution to this and people say to use <code>&lt;%# %&gt;</code> instead of <code>&lt;%= %&gt;</code>. I tried to do this and get the following error.</p>

<pre><code> &lt;a runat="server" href="#" onserverclick="deleteScheduleField" class="&lt;%# scheduleField["id"] %&gt;"&gt;
</code></pre>

<blockquote>
  <p>The server tag is not well formed.</p>
</blockquote>

<p>To test my code behind works i created the following function and this works perfectly if i enter a non dynamic id.</p>

<pre><code>public void deleteScheduleField(object sender, EventArgs e)
{
    HtmlAnchor link = (HtmlAnchor)sender;
    Response.Write("DELETED " + link.ID );
}
</code></pre>

<p>How can i call this method and pass it a dynamic value?</p>