In an ASPX page, I am populating the rows of a table programatically by filling up a server-side string with contents and then putting it in the output HTML with a construct <tbody><%=mystring%></tbody>.
One of the <td> elements of the row is a button to delete the row, and I need to pass to the server another <td> element in the row.
In the server-side code that prepares the table, I tried with:
string RowTemplate;
RowTemplate = "<tr><td>{0}</td><td>{1}</td><td>{2}</td><td><form action=\"/submit\" name=\"removeemail{0}\" runat=\"server\"><input custom=\"{1}\" class=\"btn icon-remove\" value=\"X\" onserverclick=\"RemoveEmail\" runat=\"server\"/></form></td></tr>";
Then, as I create rows, the place holders {0}, {1}, and {2} are replaced by the row’s corresponding values.
The idea is to retrieve the “custom” attribute (the key for deletion) at the server-side function called RemoveEmail, and then build the table again without the removed row.
However, it seems that the generated HTML for this inline form is not preprocessed by ASPX engine so HTML code that reaches the browser is directly the ASPX HTML markup.
How could I have the ASPX markup preprocessed so that it behaves exactly as static ASPX markup like the one that is find an a .aspx file? If that is not possible, how could I manage server-side deletion with an inline button on a table row in ASPX?
I don’t think that by adding
runat="server"to theseHTML Controlswill make them work as server side controls. You can addrunat="server"to the markup, and that would work. This is one way I would do this:Markup:
Code Behind:
This adds the
Buttoncontrol to aTableCell, and attaches theremoveEmail()event to this button.Good luck.