views:

3790

answers:

7

I have a radio button list on a page that is used to configure products. when the page loads the first time the first list of options is displayed. you select one of them then click a "Next Step" button and the page posts back and shows a new radio button list for step 2. Now if i click a "Previous Step" button i can easily get the previous list of options to display but i can not for some reason get one of the radio buttons to be selected. I can easily bring back the value i need. right after making the radio button list i have a step that just says radiobuttonlist.selected = "somevalue" depending on whatever the user chose when they completed the first step the first time.

when i debug i see that the value is correct and is being applied. but then when the page is displayed the radiobutton is not selected.

I have noticed that when i click my "Previous" button while debugging the folowing steps occur.:

the page.load handler runs and the code inside my if not page.ispostback block does NOT run, which is correct. then the handles for the button i just clicked gets run. but then after that the page.load handler runs again but this time the code in the if not page.ispostback block DOES run...

is that normal? for the page.onload block to run twice like that on a postback? i think it may have something to do with why my value is not being applied.

A: 

Try setting AutoEventWireup="false" in the page.

ctrlShiftBryan
+1  A: 

It sounds like you are causing a redirect to happen. You aren't by chance doing a Response.Redirect in order to "get back" to the original page? This would cause the functionality you describe. You would first get the Postback from the Previous button to leave the page, and then you would get a fresh Request (IsPostback = false) as the page reloads.

Thunder3
A: 

I DID have a response.redirect i was using but i removed it. I suppose i can do a thorough check to make sure i didnt have another one anywhere. I will try the autoeventwireup property as well.

A: 

alright well it looks like the autoevenwriteup property was already set to false before i even started. so i don't think that was it.

I didn't see any other redirects happening anywhere... i guess the search continues.

A: 

Have you tried setting the selected value during the page's pre-render phase instead of Page_Load?

ipstset
A: 

Try to do this

yourRadioButonList.Items.FindByValue(YourSavedValue).Selected = true;
netseng
A: 

I had the same issue, like what Thunder3 mentioned, I did a redirect back to the page, and was calling a method on Page_Load, to set the RadioButtonList selected value. But the selected value was not applied to the RadioButtonList.

I solved the issue by calling the method on Page_Init instead.

bigfatlump