OK, I'll verify that you are on the right track. You will need to
recreate the number of rows you dynamically created during init. But,
once you've done that view state should be able to recreate everything
else.
"Any dynamically created controls must be created in Init to be
recreated after postback." Would be better stated, "Any dynamically
created control must be recreated in Init to have its state reset after
postback." Viewstate assumes the control object has been created, it is
just resetting the state of that object. Not, recreating the object AND
setting the state.
All you really need is a way to keep track of what you created
dynamically so that you can recreate it during init. You could do this
with a hidden field which you could get from
Request.Form["hiddenFieldNam e"] during Init.
-----Original Message-----
From:
mo******@gmail. com [mailto:mo****** @gmail.com]
Posted At: Tuesday, October 30, 2007 7:44 PM
Posted To: microsoft.publi c.dotnet.framew ork.aspnet
Conversation: Creating controls dynamically based on user input
Subject: Creating controls dynamically based on user input
I can think of a lot of reasons why this might need to be done but as
far as I can tell it's not possible. I've been looking for a way to
add HtmlTableRows to a table using a button click for a while and it
seems it's not possible because the row that gets added with each
click won't get recreated after a post back. After all the reading it
seems that any dynamically created controls must be created in the
Init event to be recreated after postback. This I think is very
unfortionate as it makes it impossible to change the display
interactively. Can someone please verify that this really is
impossible to do?