0
votes

I have a table that I am creating programmatically and then adding some rows and data to it in the CreateChildControls() method.It has 2 columns with dropdownlist controls in it.Now on the client side based on selection in the dropdown I am adding more rows by copying the contents of the last row.There is a save button which when clicked invokes the below overriden function of the webpart to get the table object back..The issue is the rows that I am adding on the client side are not being retrieved..Only the rows that were created on the server side initially are being retrieved.Can someone please tell me what I am doing wrong here.

So doing this Table tab = FindControl("Main1") as Table; tab.rows only give 3 which were initially generated on the server and does not include the 2 new that were created client side

Public Override Control FindControl(string id)

{

return base.FindControl(id);

}
2

2 Answers

1
votes

Any rows added client side will not be passed to the server - that is the way in which the technology works. A better way to do this would be for the save button to generate a PostBack and add the new rows on the server.

If the new rows absolutely have to be added client side then you will need to write an ajax call to add the new rows to the viewstate server side after they have been added client side - seems like a lot of work when a PostBack should be perfectly adequate.

0
votes

I believe the controls added server-side are stored in ViewState, and client-side DOM changes don't affect that. It would probably be easiest for you and the best user experience to add an UpdatePanel around your table and dropdowns, and add the rows server-side.