Adding controls on postback

Rainverse
Rainverse used Ask the Experts™
on
I'm creating a webpart for Shareoint 2007.  I have 2 radio buttons being displayed on initial load, created in the CreateChildControls method.  What I would like to do is load different controls on to the form based on whichever radio button they click. I can read a correct Checked property in an event handler of the radio button checkChanged event, but I can't read a correct one in the CreateChildControls method on postback.  I tried setting a class level boolean variable in the checkchanged event and then reading it in the CreateChildControls method, but the checkchanged event fires AFTER CreateChildControls, so that's no help.  

Anyone know how to accomplish this?  Let me know if that wasn't clear.  I just re-read it and it seems a little confusing...

-MJC
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
In general we created all the controls and just hid them all to start, then showed as the radio was changed.  That way you have a lot less issues with the form changing on postback...
Rajendra ShekhawatSolution Architect

Commented:

Hi,

I would suggest use CreateChildControls to create all the controls, including the controls you want to create on the options chosen by the radio buttons.

Use Page PreRender event to manipulate the controls based on the class variable set on the butthon checkChanged event.

Cheers ...
Rajendra

Author

Commented:
What I ended up doing was setting the ChildControlsCreated property to False at the end of my checkChanged event handler.  I found this solution here: http://www.dotnet247.com/247reference/msgs/53/266706.aspx

Does anyone know of a reason this might be a bad idea? It appears to work.  

-MJC

Author

Commented:
By the way, both of the above solutions look good as well.  I would probably lean towards the preRender option, simply to avoid client side code with the showing and hiding solution.  

-MJC

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial