I have a webpart that does the following.
1. Retrieve a current record from a web service call
2. Provide a form to update that information
3. Save the record via web service.
The challenge is that one or more values in the record determine what
the form will look like. For example if the car make is Ford then I
would show a list of models for that make, which would need to be
retrieved via a web service.
So I have a listbox of "auto makes" with an event attached to
retrieve the models for that make on change.
The problem is that I am creating the form in CreateChildControls and
in the web part life cycle the post data is not updated until after
CreateChildControls has been done. Therefore I do not have the
change to the car make listbox when creating the page.
If I were to make ChildControlsCreated false then I can recreate the
controls, however any post data will be cleard from controls that I
add to the collection again.
Here is the solution that I came up with.
A) First request of part - ViewState["rec"] is not set
1) Get record from web service
2) Store record in viewstate
3) CreateChildControls based on ViewState
B) ChangeEvent Postback - ViewState["rec"] is set
1) CreateChildControls based on viewstate
2) Move Post data to ViewState
3) Process Event and store to viewstate
4) CreateChildControls based on viewstate
What do you think of this approach? Has anyone else come across the
same situation and what approach did you use?