How can I get the contents of my table with dynamic row adding?
how to retrieve from the server-side contained a table html constructed this way:
<table id="myTable" >
<tr>
<th> <input type="text" value="name开发者_如何学Python"/></th>
<th> <input type="text" value="quantity" /> </th>
</tr>
<tr>
<th> <input id="name_1" value="phone" /> </th>
<th> <input id="quantity_1" value="15" /> </th>
</tr>
<tr>
<th> <input id="name_2" value="mp3" /> </th>
<th> <input id="quantity_2" value="26" /> </th>
</tr>
</table>
I can not make use of <asp:Table> ...
because for technical reasons I did not find a solution following this post: How to dynamic adding rows into asp.net table?
How can retrieve the contents values of my table (dynamic) for each row. Rows will be added in client-side js
Thank you.
short answer, you can't using classic asp.net server model even if your table had a runat=server tag.
since a table is not a input control, asp.net framework does not keep track of changes to it on the client after post back. in fact, after the postback the new changes will be lost on next page load.
however there are many ways you can pass/obtain this info on the server.
you could, keep track of the table changes somewhere else, like a hidden input field. so whatever javascript you use to update your table, have it also save the information to a asp.net hidden input control. than after postback you can read it from there and parse as you please.
Put a runat="server" into the tag.
<table id="myTable" runat="server>
More details here: http://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmltable(v=vs.71).aspx
Use the Request.Form("name_1") to get the value...
精彩评论