0

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:

  • I created a method to wipe all textbox.text values using table.findcontrol(). When tied to a button, this method works to spec (which indicates findcontrol is able to find/update the textboxes,) though all affected textboxes remain the blank if the page is reloaded. If placed in the page load, the method does nothing (textboxes retain their former values.) In debug mode, findcontrol pulls a value when used on the button, but comes up null when added to pageload. I have done this with table.rows.clear() commented and uncommented.
  • I have also attempted to throw all the code into oninit. This doesn't seem to make any appreciable difference.
1
  • It would be helpful to see what your Page_Load event looks like. But my guess is that you're not re-creating the textboxes after every load. Commented Jan 14, 2013 at 22:17

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.