postback find dynamic control problem

  • Thread starter Thread starter PCH
  • Start date Start date
P

PCH

I have an c# asp.net (.net 1.1) web page, viewstate on.

The problem I am having is on the button click postback to update.

Heres the situation:

I have an asp table that has 1 header row.

On load I loop through a count, say 0 to 3, and dynamically build rows, into
the asp table.
For each row there are a few cells. for each cell there is/are a textbox
control(s), etc etc.

it builds great, everything works well for display.

When it posts back on a button click, I can no longer access those dynamic
controls.

I tried looping recursively through parent controls, but they dont exit,
they are lost on postback. The recursive loop finds every single control on
the page except those that I build dynamically and add to the ASP table
dynamically.

I also tried the request form object to look at each key. From that I can
find the control keys/values, EXCEPT for those controls I designated as
hidden, which i need!

Any ideas?

Thanks
 
You are correct. The controls are gone after postback.
That's just how it works.
When you dynamically create controls, you are expected to dynamically create
them again upon postback.
It shouldn't be too hard if you design carefully. You should be able to
reuse the code that creates the controls in the first place.
 
No, recreate the controls on postback, but let ASP.NET fill in the user
selected values automatically.
Then you can examine the control values normally.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
 
So that means you shouldn't create user controls for Items that use a
Database to retrieve values for it. I.e. you will end up accessing the
database on every postback?
Isn't this a major flaw for user controls?
Is there any around this?
 
Back
Top