Reputation: 7546
In my .aspx
file I have the table
below:
<table id="table1" style="width: 100%;" runat="server"></table>
I want to access this table and insert html into this table in C#(.aspx.cs)
,I tried this:
HtmlTable table = (HtmlTable)(form1.FindControl("table1"));
table.InnerHtml = "<tr><td></td></tr>";
But I got NotSupportedException
. How can I solve this?
Upvotes: 0
Views: 1902
Reputation: 2475
If you want to be able to retrieve the table in the code-behind, you need to use a .Net control and declare your table using
<asp:Table runat="server" ... />
...
</table>
Upvotes: 1
Reputation: 399
If the control does not have a runat="server" your code behind will not be able to access the object at runtime. :)
Upvotes: 4
Reputation: 2321
use runat server to make the table available serverside
<table runat="server" id="table1" style="width: 100%;"></table>
For reference you could take a look at this SO question - Why does ASP.NET webforms need the Runat=“Server” attribute?
Upvotes: 3