View Single Post
  #2 (permalink)  
Old November 29th, 2004, 01:06 PM
planoie's Avatar
planoie planoie is offline
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

The items in your datalist (and subsequently the textboxes that are in each item) get recreated at the beginning of page creation. They also get created when you bind the control. On a postback, the control hierarchy (datalist, items, textboxes) is recreated from viewstate. However, their values are filled in by the postback handler which gets them out of the form's posted data. So during "ItemCreated" you may very well not see the data.

If you want to be able to harness the changed state of a textbox, you need to wire the textbox OnChange handler to a server side event. You can do this by adding an event handler to the textbox during the OnItemCreated event of the datalist. Then, when the page enters the "raise postback events" stage of the page lifecycle, any textbox that has actually changed will raise the change event and thus call the method you wired to it.