postback find dynamic control problem

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
 
S

Steve C. Orr [MVP, MCSD]

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.
 
S

Steve C. Orr [MVP, MCSD]

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
 
R

ree32

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?
 

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,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top