在我的收货地址页面上有两个RadioButtonList ListItems(下面显示的代码)根据用户输入写入数据库true或false。Asp.Net RadioButtonList选择的ListItem页面上不能识别
用户第一次选择一个值并转到结帐过程的下一步时,他们的发货地址类型会正确存储在数据库中(true/false)。如果他们返回送货地址页面,请选择相反的ListItem并转到下一个结账页面,其更新的送货类型在数据库中不会更改。就好像ListItem不能识别用户的单选按钮选择在重新访问页面时已经改变。
有人可以帮忙解决这个问题吗?
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;
}
}
}
该问题表明与页面生命周期有关的误解/错误。与给定的信息不能帮助! – humblelistener
可能需要更多信息...您的代码隐藏中的PageLoad事件处理程序是什么样子的? – Brian
我编辑帖子,添加上面的页面加载事件处理程序。谢谢! – Joe