Link to home
Start Free TrialLog in
Avatar of Rainverse
Rainverse

asked on

Adding controls on postback

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
ASKER CERTIFIED SOLUTION
Avatar of mrichmon
mrichmon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

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
Avatar of Rainverse
Rainverse

ASKER

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