ASP. Net gurus? Problem with ViewState

G

Guest

Hi,
I am using ASP.NET 2.0 with C#. ViewState is not working for controls
created at runtime.
On a page I have a few (static) textboxes that get populated from database
and then I create other textboxes during runtime using the folloiwng steps:
1. I add a TableRow(TR) to an existing table using HtmlTableRow
2. I add TableCells(TD) to the above TR using HtmlTableCell
3. I add TextBoxes to the TDs using using TextBox

Then I start entering into the runtime Textboxes, when done, I press Enter
which does a postback. Now I am back at the page and my first list of static
textboxes are still there while the runtime textboxes and the TR and TDs are
gone. If I try to recreate the TRs with the same name as before, I get an
invalid ID meaning that the TR is still on the form. I just don't see it.

How would I presere the runtime web controls upon postback? How would I see
them?

Thanks
 
J

Jon Paal

make sure you call those creations again in the postback section or they won't be created
 
O

Olaf Rabbachin

Hi,
How would I presere the runtime web controls upon postback? How would I see
them?

controls that you add during a page's runtime won't "survive" a postback.
That is, you'll have to recreate them every time.
I guess that you create your controls in the Page_Load-event, but within a
<if (!Page.IsPostBack) {...}>-block. Move the creation of your
runtime-controls out of that block so they're called everytime the page is
being created and sent.

Cheers,
Olaf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top