Error in table when adding runat=server

Bat_Programmer picture Bat_Programmer · Sep 27, 2012 · Viewed 17k times · Source

I have a html table in my ASPX page and would like to use it in code-behind for some processing. The table is shown as below:

<table class="hovertable" id="tblData">
    <tr>
        <th>ID:</th>
        <td colspan="3" style="font-weight: bold">
            <%= Eval("ID") %>
        </td>
    </tr>
    <tr>
        <th>Date:</th>
        <td><%# Eval("Date", "{0:dd-MMM-yyyy}") %></td>
        <th>Amount:</th>
        <td><%# Eval("Amount", "{0:C}") %>
    </tr>
</table>

However, when I add the runat="server" attribute to my table, I am produced with the following error:

CS1502: The best overloaded method match for 'System.Web.UI.HtmlControls.HtmlTableRowCollection.Add(System.Web.UI.HtmlControls.HtmlTableRow)' has some invalid arguments

Any ideas what may be wrong here? Am I missing out anything?

Answer

Rob Angelier picture Rob Angelier · Sep 27, 2012

An html table (which is not a pure asp.net server control) can't contain asp.net server controls. Take a look at this answer:

http://forums.asp.net/t/1524580.aspx/1

In my opinion, you should ask yourself the following question?

Do i need to solve this client or server side?

if your answer is client, you should implement the update logic with Ajax, otherwise you could use the ASP.NET server control and implement it server side.