How can I gatherinformation from a dynamically created user contro

G

Guest

I have a user control which holds information about a single well of a 96
well plate (http://en.wikipedia.org/wiki/Microtiter_plate) . The user control
has a couple of input fields which users can set to specify what is in that
particular well. Since I want 96 of them displayed on the page, I am creating
them and adding them to TableCell objects which are then put into a Table
object.
I want the user to be able to make all adjustments to the whole set of 96
user controls and then click a single button to enter that information into a
database. The problem is that when the click the button on the parent page,
all of the user controls have vanished! They are not persisted through the
PostBack!
I know I can reinstantiate them, but then they will be in the state in which
they were originally loaded, they won't keep the user's changes.
I have been able to gather information from them, but only is it is input
fields and even then I have had to iterate through Request.Form.AllKeys and
parse out control names to figure out where I am.
The user control has a Well object which has a InsertIntoDatabase method I
would like to use, but I can't figure out how to do so. Is it possible to
call a method from an object which is a property of a user control onPostBack
of the parent page?

Thanks!
Ethan


Ethan Strauss Ph.D.
Bioinformatics Scientist
Promega Corporation
2800 Woods Hollow Rd.
Madison, WI 53711
608-274-4330
800-356-9526
(e-mail address removed)
 
G

Guest

Hello Ethan,
Here are some tips that you should ttake to heart.
First off - controls are not saved upon postback. Their content is but the
controls are not.
Therefore you must recreate them every time.
Also - it is recommended that controls be created in the on Init event
Make sure that you give all of the controls an id. A control should get the
same ID it had last time. Make sure these controls are added to the control
hierarchy also at this time.
This way they can play "catch up" with all of the events such as
loadviewstate , etc

Also, make sure your UserControl is implementing INamingContainer.
This is a methodless Interface that tells asp.net that this control needs
its own naming container. This helps to avoid name collusions, etc

Hope this helps.
 
G

Guest

Thanks for the reply, but I am still a bit confused.
You say that the control's content is saved, but not the control, I don't
understand how I can/should recreate them in the Init event. If I reload them
using LoadControl(), won't I be replacing the content of each field within
the control with the default value? Or will it somehow stay the same if I
keep the ID constant?
Also, I need some information from other form fields in order to even know
how many controls there are. When I try to get this information in Page_Init,
it does not appear to exist yet.
If there was some working code (C# preferred) which does this, I would love
to see it.
Thanks again,
Ethan
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top