Suraj
Suraj

Reputation: 89

Retaining viewstate in textboxes found in a dynamically created table

My problem is that I have an ASPX page which contains an ASP:Table. The rows for the table is added dynamically on Page_Load. One column in the table contains TextBoxes, BUT when I type something on a TextBox and cause a postback, I am unable to find the value just entered. And above that the table is not displayed after the postback.

Can anyone help me please? I want to keep the table viewstate with the modified textbox values, so that when i post back to server, I can intercept these new values.

Thanks in advance, Kevin

Upvotes: 0

Views: 2492

Answers (3)

Bryan
Bryan

Reputation: 8778

Dynamic controls need to be added during the Init event (and on every load) if you want ViewState to track anything, because ViewState is restored before Page_Load.

However, TextBox values are found in the post data, not the Viewstate. This is a common misconception. The same rule applies though.

Upvotes: 0

Anders Fjeldstad
Anders Fjeldstad

Reputation: 10814

Are the rows of the table (or the table itself) added at every Page_Load? They should be, if you want them to work correctly between postbacks.

Edit: With the same IDs, as another answer pointed out.

Upvotes: 0

Codesleuth
Codesleuth

Reputation: 10541

You will need to ensure you re-create the textboxes with the same IDs, and then you should be able to find the value. For example, if you are using TextChanged events, these will fire so-long as the textboxes are re-created each time and have the same IDs.

Upvotes: 2

Related Questions