ViewState - Add/Remove Control

M

mnichols

Hello,

In an ASP.NET form I have:
- a table that contains rows of controls
- each row has an sequence number that the user can modify
- the rows should be ordered by the sequence number
- the table and the controls on each row are created dynamically

My questions is, what is the best way to determine on Postback the
modified sequence number values so that the table can be recreated with
the rows in the right order?

I can see a few options at my disposal:

A. Manually get sequence number values from the Request[] collection
before recreating the table; or
B. Recreate the dynamic controls in Page_Init() method and add them to
the Page's Control collection so that their ViewState is restored. Then
in the Page's Page_Load method recreate the table and remove the
previously created controls from the Page's Control collection and add
them to the Table's TableCell's Control collection (a move rather than
create-destroy-create).
C. Recreate the whole table in Page_Init() and then add and remove the
rows based on the news sort order (again a move).

Any opinions on the best way to do this?

Currently, I am using step B and found that it works except that
ViewState is restored a second time when the control is moved from
Page.Controls to TableCell.Controls. I have a hunch that happens because
I was not setting ChildControlsCreated to true in my custom control -
but have yet to test the theory.

Thanks in advance,

mnichols
 

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

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top