Related Dynamic Controls / Viewstate Problem

G

Guest

I'm creating a set of dynamic controls on a webpage by calling my
BuildControls sub in the Page_Init sub. I recreate the controls by calling
the BuildControls sub in the LoadViewState override procedure. The set of
controls will not always be the same (based on the selection the user makes
in a static ddl). The controls are persisted perfectly.

The problem I'm experiencing is that when one of the dynamic ddl's (let's
say ddl1) is changed I want to save the value selected so that I can use the
value when the BuildControls sub runs to populate another ddl control (let's
say ddl2) in the LoadViewState procedure. I'm attaching a SelectIndexChanged
event to ddl1 and setting it's AutoPostBack property to "True". The problem
is that in the LoadViewState proc. ddl1 doesn't seem to exist. I've been
reading a lot about the page execution cycle, but I'm stumped as to where to
save the selected value of ddl1 so that I can use it when I rebuild my
controls (and repopulate ddl2).

I even tried running the BuildControls sub in my SelectIndexChanged event
since it runs after the LoadViewState sub and the controls exist at this
point. The problem then is I get 2 sets of the same controls. One set is
populated correctly and the 2nd has the original defaults.
 
G

Guest

Ok, I solved my own problem. In the SelectedIndexChanged event of my dynamic
ddl (ddl1) I can get th id and value of the sender object and store it in
viewstate. In my BuildControls sub (also called from the
SelectedIndexChanged event) I check to see if this is a postback and if so
then enumerate the controls on the page looking for a match for the control
id for the one that it is trying to create. In the sub that populates ddls I
check in viewstate to see if "ddl1" exist and if so get it's value from
viewstate and use it in the select statement to populate ddl2.
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top