RadioButtonList: OnSelectedIndexChanged not firing

Yann picture Yann · Jul 7, 2011 · Viewed 7.6k times · Source

I have an aspx page where i dynamically add a radiobuttonlist with OnSelectedIndexChanged event. In the event i check for the selected items. i have 2 items.

For the first item,the event is firing well, However if i choose the other option the event is not firing: below the code..

The event is only firing is i change from "Some provided" to "All provided" the other way it is not working

Adding the RBL:

                RadioButtonList dControl_b = new RadioButtonList();
                dControl_b.ID = "rbl_MinCriteria";
                dControl_b.RepeatDirection = System.Web.UI.WebControls.RepeatDirection.Horizontal;
                dControl_b.CssClass = "Font";
                dControl_b.Font.Name = "Arial";
                dControl_b.Font.Size = 8;
                dControl_b.ToolTip = "";
                dControl_b.SelectedIndex = -1;
                dControl_b.SelectedIndexChanged += new EventHandler(rbl_MinCriteria_SelectedIndexChanged);
                dControl_b.AutoPostBack = true;

Checking the selected item:

   if(rbl_MinCriteria.SelectedItem.ToString() == "All provided")
   {
       cbl_MinimumCriteria.Items[0].Selected = true;
       cbl_MinimumCriteria.Items[1].Selected = true;
       cbl_MinimumCriteria.Items[2].Selected = true;
       cbl_MinimumCriteria.Items[3].Selected = true;
       cbl_MinimumCriteria.Enabled = false;

       //*************************************************************
       if (ddl_CountryOccurence.SelectedValue != "Please choose")
       {
           ddl_CountryOccurence.Enabled = false;
       }
       else
       {
           ddl_CountryOccurence.Enabled = true;
       }

       //*************************************************************
       if (tb_DueDate.Text != "")
       {
           tb_DueDate.Enabled = false;
       }
       else
       {
           tb_DueDate.Enabled = true;
       }

       OtherControlI.Enabled = false;
       OtherControlII.Enabled = false;
       OtherControlIII.Enabled = false;
   }
   if (rbl_MinCriteria.SelectedItem.ToString() == "Some provided")
   {
       cbl_MinimumCriteria.Items[0].Selected = false;
       cbl_MinimumCriteria.Items[1].Selected = false;
       cbl_MinimumCriteria.Items[2].Selected = false;
       cbl_MinimumCriteria.Items[3].Selected = false;
       cbl_MinimumCriteria.Enabled = true;

       //*************************************************************
       if (ddl_CountryOccurence.SelectedValue != "Please choose")
       {
           ddl_CountryOccurence.Enabled = false;
       }
       else
       {
           ddl_CountryOccurence.Enabled = true;
       }

       //*************************************************************
       if (tb_DueDate.Text != "")
       {
           tb_DueDate.Enabled = false;
       }
       else
       {
           tb_DueDate.Enabled = true;
       }

       OtherControlI.Enabled = false;
       OtherControlI.SelectedIndex = -1;
       OtherControlII.Enabled = false;
       OtherControlII.SelectedIndex = -1;
       OtherControlIII.Enabled = false;
       OtherControlIII.SelectedIndex = -1;
   }

Any help and Comment is much appreciated

Answer

trgraglia picture trgraglia · Jul 26, 2012

This is for people who find this question from Google:

On the RadioButtonList, set the AutoPostBack property to true.

RadioButtonList OnSelectedIndexChanged