views:

525

answers:

1

Hi there,

I hope you can help. This has been confounding me for hours.

I have a RadioButton list in my CustomerGroupConfirm.aspx page:

<div>
    <table>
        <tbody>
            <tr>
                <td nowrap="nowrap">
                    <asp:RadioButtonList ID="rblContractGroups" runat="server"></asp:RadioButtonList>
                </td>
            </tr>
            <tr>
                <td nowrap="nowrap">
                <br />
                    <asp:Button ID="btnConfirmCustomerContractGroups" runat="server" OnClick="confirmCustomerContractGroups_Click" CssClass="Button" Text="Confirm Default Customer Contract Group" />
                </td>
            </tr>
        </tbody>
    </table>
</div>

I select a RadioButton and when I click on the button "Confirm Default Customer Contract Group" here is the function in code-behind which fires:

protected void confirmCustomerContractGroups_Click(object sender, EventArgs e)
{
    // Iterate through the Radio Button list.
    foreach (ListItem li in rblContractGroups.Items)
    {
        if (li.Selected)
        // If the Radio Button List Item (Customer Contract Group) is Selected.
        {
            // Set the Default Customer Contract Group of the Current User.
            CustomerAccess.SetDefaultCustomerContractGroup(Int32.Parse(Session["CustomerID"].ToString()), Int32.Parse(li.Value));
        }
    }
    Response.Redirect("~/Default.aspx");
}

The problem is that the List Item (li.Selected) is always false.

What am I doing wrong? Can anyone help please.

Kind Regards

Walter

+1  A: 

Maybe you're binding your rblContractGroups radiobuttonlist in every postback. You should put it into IsPostBack control :

if (!Page.IsPostBack)
{
    // Bind your rblContractGroups
}
Canavar
You are absolutely correct. Thank you so much.
Walter Lockhart