I have an HTML table and insert a row using Javascript via the onclick event of a button. This is my code. HTML:
Solution 1:
the main reason can be fured out by post in the comment by Amir Sherafatian:
when the website is created, all html is rendered - the elements that have runat="server" attribute have 1:1 objects generated sever side during page execution.
Mind you, page execution ends when the html is written to the client and then unless you store some data in Cache /Session/ ViewState/ cookies or any other persistent storage all the data regarding the rendered page is lost on the web server.
when client clicks submit the state of the page is recovered from those persistent storages and inputs that are on the webpage (which is basically a form hence every postback sends ALL inputs / selects / hidden fields back to the server) Imagine, that the user modifies your page via own java script using console - it simply cannot be accepted bu the server. the html means nothing to the web server on postbacks. The only mean of communication is via postback attributes which are mapped from form fields.
any other objects that are not input fields / hidden fields are rebuild from the aspx/html (on your server) somewhere along begining page execution.
Your code behind sees only header row because only header row is defined in the table from which the state of the page is built.
if you want to achieve your goal, you need to define at least one hidden field with runat=server" to which you'd add / remove data as you add / remove rows with JavaScript. Its data will then be sent as a form postback argument to the server. There you can access it just like accessing a hidden field (as i explained the hidden field value will be rebuild from postback arguments), read the data, parse it and do whatever you want.
If you want a sample code ( ASP.Net C#), please shout :)
Post a Comment for "Why Can The Row In A Html Table Not Be Read From Code Behind (vb.net)?"