views:

297

answers:

4
+2  A: 

Make sure your page has

EnableViewState=True
brendan
yes, the view state is enabled.
Rich
A: 

Last time I needed ViewState for a Radio Button I had to override the LoadViewState and SaveViewState methods to get it to work correctly.

IrishChieftain
+2  A: 

First off, this is NOT a ViewState issue. Viewstate is for programmatic changes to the controls on a page. If you set the text of a label to something different than what resides on the ASPX in CODE BEHIND then that value is stored in viewstate. .NET has a mechanism (and it's controlled via an interface that your control needs to implement) which parses out the POST data back to the controls where it belongs which occurs after ViewState has been loaded but before the Page_Load event fires.

Now, there's a couple different possibilities for the reasons behind this:

First, is this radiobutton inside your custom control being generated inside the CreateControls method or is it straight HTML that your control is rendering? If it is straight HTML then you'll need to ensure that you're handling the expected values as they come back from postback. If it is a server control being declared as NEW inside your custom control and not being instantiated and dealt with in the CreateControls method then you need to mvoe it there.

Second is this control on the ASPX page or is it being added to the page in the code behind. If it is being added to the page in code behind it's probable that it's being added after the .NET parser has finished handing out the postback data. Check your forms collection to see if the value exists there.

Stephen Wrighton
I Stephen, I've added and addendum to the original question which fills in some of the questions you asked and a little more.Cheers
Rich
+1 for stating that ViewState isn't used to persist the state of a control across postbacks. ControlState is used for this.
Rich
Stephen/Rich, Is this really control state? Isn't this standard post data sent back in the POST request? Does the radiobutton control use control state in asp.net 2.0 for storing state as opposed to asp.net 1.1 ?
Preets
Preets - the value is stored in the FORMS POST collection. 2.0's CONTROLSTATE is a different beast, and is basically a ViewState that cannot be disabled. It is used to store ESSENTIAL information that 1.1 controls would have stored in ViewState (such as a pager's PageIndex).
Stephen Wrighton
A: 

Got a response from the developer that took over the project ->

"Your quiz control was fine mate, the reason the values weren't being retained on postback was because of inherited functionality in the base class when you put it live. Essentially it did a DataBind in the page load method which in the page lifecycle is before the postback meethods get called, so it reset the values of the dropdowns. In the end I set up some viewstate properties which held the values of the dropdowns. So it wasn't something you could have known about."

Hope this helps someone.

Rich