user1978597
user1978597

Reputation: 1

ASP .Net - Change/Update Dynamically Created Textbox

OK, got pretty far on this one, but need an assist from someone with superior ASP skills. I'm using code behind to populate an ASP table with the results of a SQL query. The read-only values are stored in the .text of some of the table cells, while read-write values are stored in .text of textbox controls (dynamically created and added to table cells.)

This works fine on the first load. When the page reloads with a different query (for example: a user selects a different column to order by,) the table cell values repopulate correctly, while the textbox values remain unchanged. Throwing in a table.rows.clear() prior to the query does not seem to fix this.

More info:

Upvotes: 0

Views: 1418

Answers (2)

Jfetner
Jfetner

Reputation: 55

In order for dynamic controls to retain their values you need to:

a.) Ensure Viewstate is enabled for the page. b.) Recreate the controls on every page load ensuring you create the controls with the same IDs as were given to the controls originally. Also you need to do this before the viewstate is loaded (preferbly in the Onit or PreInit method. See the page life cycle here: http://msdn.microsoft.com/en-us/library/ms178472%28v=vs.100%29.aspx

Upvotes: 0

Ulises
Ulises

Reputation: 13419

Dynamic controls must be added on each page request, preferably during the Init event. It sounds like you are not recreating them on time.

Add them on every single page request and, as part of the page life cycle, they will receive their values from the viewstate

Upvotes: 2

Related Questions