On my shipping address page there are two RadioButtonList ListItems (code shown below) that write to a database true or false based on user input.
The first time a user selects a value and moves to the next step of the checkout process their ship to address type is stored correctly (true / false) in a database. If they go back to the shipping address page, select the opposite ListItem and move on to the next checkout page, their updated shipping type is not changed in the database. It is as if the ListItem does not recognize the user’s radiobutton selection has changed when revisiting the page.
Can someone please help figure this one out?
ShippingAddress.ascx
<asp:RadioButtonList id="ShipToAddressType" runat="server">
<asp:ListItem Value="0" id="businessShipping">My shipping address is a business.</asp:ListItem>
<asp:ListItem Value="1" id="residenceShipping">My shipping address is a residence.</asp:ListItem>
</asp:RadioButtonList>
ShippingAddress.ascx.cs
if (residenceShipping.Selected == true)
shippingAddress.Residence = true;
else
shippingAddress.Residence = false;
ShippingAddress.ascx.cs Page_Load
protected void Page_Load(object sender, EventArgs e)
{
User user = Token.Instance.User;
Address shipAddress = null;
foreach (Address tempAddress in user.Addresses) if (tempAddress.Nickname == "Shipping") shipAddress = tempAddress;
// sets radio button of return users previously selected ship type
if (shipAddress != null)
{
if (shipAddress.Residence == false)
{
ShipToAddressType.SelectedIndex = 0;
}
else
{
ShipToAddressType.SelectedIndex = 1;
}
}
}
You need to move the code in
Page_LoadtoPage_Init. OtherwiseViewStatewon’t work and you won’t get change events. View state is loaded afterInitbeforePreLoad.You should also wrap your init code in a
IsPostBackcheck. Although I may misunderstand what you are doing here.