Post Back Predicament

T

tyler.lloyd

Hi,

I am trying to develop an asp.net 2.0 page that dynamically adds
controls (Textbox Fields) to a page depending on items selected from a
treeview. I have however run into a bit of a tricky problem, I require
the controls to be added in a certain order (some controls should be
above others). This causes all kinds of fun when the data is posted
back. If a new control was added and it is positioned before existing
controls on the page it causes the control IDs to become de-synced.

For Example: A user adds five controls and fills in the text fields
then decides to add another control. When the new control is added all
the previously enter data disappears as all the control IDs no longer
match. (I tried setting the Control ID manually; it must be using
another ID)

The only way I can see around this is to pre-populate the whole page
with every control then hide the ones not selected (But this would not
scale well at all). Does anyone have any ideas? Or am I missing
something simple?

Any help would be most appreciated.
Thanks
Tyler
 
E

Eliyahu Goldin

Tyler,

Did you consider putting the controls in a repeater? You could make a
datasource that would hold data necessary for creating the controls and
databind the repeater to that datasource. The controls could be arranged in
the repeater item template and the repeater would build as many items as
required.
 
G

Guest

Why are you so concerned with the control ID's?

One solution could be use the Command event instead of the Click event and
then capture the CommandArgument and CommandName to ascertain how to react to
that button in your code.

So let the CommandArgument and CommandName tell your code how to react in
other words.
 

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,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top