title: RadioButtonList Postback Issues
body: <p>Environment: ASP NET 2.0 - Production Server does not have Ajax Control Toolkit so no real Control toolkit to use here. </p>
  
  <p>3 RadioButtons List:
  List one loads, after postback, the item from list one is used to select a Lab value. 
  Once a lab value is selected a 3rd radiobuttonlist will populate.  There are some textboxes but they are not shown in example.  The textboxes postback themselves on changes.  If both textboxes are
  not empty, a record is created for the session. </p>
  
  <p>Now if the 3rd radiobuttonlist is changed from the default a series of 3 hidden user controls appear which represent 3 levels of reasons for the change ( child/parent records in database ). </p>
  
  <p>The problem I am having is when I select a different item on the radiobuttonlist the radiobutton 3 OnSelectedIndex is firing after my user controls fire.  My user controls need the value of the 3rd list to go to the database and get the correct set of records associated with the lab. </p>
  
  <p>The problem is because the last radiobuttonlist is not processed until after the web controls loads, the code to mount the user controls never happens.  </p>
  
  <p>Here is the basic HTML code: 
   
          </p>
  
  <pre><code>    &lt;asp:RadioButtonList ID="rdoLab" runat="server" OnSelectedIndexChanged="rdoLab_OnSelectedIndexChange"&gt;
      &lt;/asp:RadioButtonList&gt;
      &lt;asp:TextBox ID="textbox1" runat="server" OnTextChanged="TextBoxProcess" /&gt;
      &lt;asp:TextBox ID="textbox2" runat="server" OnTextChanged="TextBoxProcess" /&gt;
      &lt;asp:RadioButtonList ID="rdoPrimary" RepeatColumns="3" OnSelectedIndexChanged="rdoPrimary_OnSelectedIndexChanged"  runat="server"  ToolTip="Select Normal, Hypo or Hyper - Normal is default value." AutoPostBack="True" &gt;
          &lt;asp:ListItem Value="3" Text="Normal" Selected="true"/&gt;
          &lt;asp:ListItem Value="1" Text="Hypo" /&gt;                                
          &lt;asp:ListItem Value="2" Text="Hyper" /&gt;
      &lt;/asp:RadioButtonList&gt;
       &lt;asp:Panel ID="UpdLab" runat="server" Visible="true"  EnableViewState="true"&gt;
              &lt;asp:Table ID="tblAdmin" runat="server"&gt;
                  &lt;asp:TableRow&gt;
                        &lt;asp:TableCell runat="server" id="tblCell1" Visible="false" CssClass="tdCell"  VerticalAlign="top"&gt; 
                              &lt;uc1:Lab ID="Lab1" runat="server" EnableViewState="true" EnableTheming="true" /&gt;                                            
                        &lt;/asp:TableCell&gt;
                        &lt;asp:TableCell runat="server" ID="tblCell2" Visible="false"  CssClass="tdCell" VerticalAlign="top"&gt;
                              &lt;uc1:Lab ID="Lab2" runat="server" EnableViewState="true" EnableTheming="true" /&gt;
                         &lt;/asp:TableCell&gt;
                         &lt;asp:TableCell runat="server" ID="tblCell3" Visible="false"   CssClass="tdCell" VerticalAlign="top"&gt;
                              &lt;uc1:Lab ID="Lab3" runat="server" EnableViewState="true" EnableTheming="true" /&gt;
                         &lt;/asp:TableCell&gt;
                  &lt;/asp:TableRow&gt;
              &lt;/asp:Table&gt;
  
      &lt;/asp:Panel&gt;                            
  </code></pre>
  
  <p>Here is the page behind: </p>
  
  <pre><code>protected override void OnPreLoad(EventArgs e)
      {
          base.OnPreLoad(e);
          GetSessionVars();
  
          if (CommonUI.strTest((string)Session["rdoLabs"]) &amp;&amp; CommonUI.strTest((string)Session["rdoPrimary"]) &amp;&amp; Convert.ToString(hrdoLabs.Value) == (string)Session["rdoLabs"])
          {
              divLabLvl.Visible = true;
              // Get cboListItems from the web user controls...
              Session["ArrLstItems"] = "";
              ArrayList ArrLstItems = new ArrayList();
              ArrayList GetWuc = GetWUCS();
  
              for (int i = 0; i &lt; GetWuc.Count; i++)
              {
                  Lab wuc = (Lab)GetWuc[i];
                  CheckBoxList cboItemList = (CheckBoxList)wuc.FindControl("cboItems");
                  string cboItems = GetCboItemList(cboItemList);
                  HiddenField hcboItems = (HiddenField)wuc.FindControl("hcboItems");
              }
              Session["ArrLstItems"] = (ArrayList)ArrLstItems;
          }
  
      } 
      protected void Page_Load(object sender, EventArgs e)
      {
  
          if (!IsPostBack)
          {
              DbDataReader ddrGrp = rdoGroups();
              if (ddrGrp.HasRows)
              {
                  rdoGroup.DataSource = ddrGrp;
                  rdoGroup.DataBind();
              }
              ddrGrp.Close();
          }
          else
          {
              DbDataReader ddrLab = rdoUserLabs();
              if (ddrLab.HasRows)
              {
                  rdoLabs.DataSource = ddrLab;
                  rdoLabs.DataBind();
                  if (CommonUI.strTest((string)Session["rdoLabs"]))
                  {
                      if (Convert.ToInt32(Session["rdoLabs"]) &gt; 0)
                      {
                          rdoLabs.SelectedValue = (string)Session["rdoLabs"];
                          SetLabCss();
                      }
                  }
              }
              ddrLab.Close();
          }
  
      }
  
      protected void rdoGroup_OnSelectedIndexChanged(object sender, EventArgs e)
      {
          //...do some stuff
      }
  
      protected void rdoLabs_OnSelectedIndexChanged(object sender, EventArgs e)
      {
          //... reload 
      }
  
      protected DbDataReader rdoGroups()
      {
  
          int group_type_id = GroupTypeId();
          Group grp = new Group();
          return grp.GetGroups(group_type_id);
  
      }
  
      protected DbDataReader rdoUserLabs()
      {
          RadioButtonList rdoGrp = (RadioButtonList)CommonUI.FindCtrlRecursive(this.Master, "rdoGroup");
          int GroupId = Convert.ToInt32(rdoGrp.SelectedValue);
          LabAbnormalReasons lar = new LabAbnormalReasons();
          return lar.GetLabsList(GroupId);
      }
  
      protected void rdoPrimary_OnSelectedIndexChanged(object sender, EventArgs e)
      {
          Session["Save"] = ((RadioButtonList)sender).ID;
          RadioButtonList rdoGroups = (RadioButtonList)CommonUI.FindCtrlRecursive(this.Master, "rdoGroup");
          RadioButtonList rdoLabs = (RadioButtonList)CommonUI.FindCtrlRecursive(this.Master, "rdoLabs");
          int UserId = Convert.ToInt32(Session["UserId"]);
          int DocId = Convert.ToInt32(Session["DocId"]);
          SubmitLab_Data(arrLstItems, arrOthers);
      }
  
      protected void GetSessionVars()
      {
  
          RadioButtonList rdoGroup = (RadioButtonList)CommonUI.FindCtrlRecursive(this.Master, "rdoGroup");
          RadioButtonList rdoPrimary = (RadioButtonList)CommonUI.FindCtrlRecursive(this.Master, "rdoPrimary");
          RadioButtonList rdoLabs = (RadioButtonList)CommonUI.FindCtrlRecursive(this.Master, "rdoLabs");
  
          if (rdoGroup.SelectedIndex != -1)
          {
              Session["rdoGroup"] = (string)rdoGroup.SelectedValue;
          }
          if (rdoLabs.SelectedIndex != -1)
          {
              Session["rdoLabs"] = (string)rdoLabs.SelectedValue;
          }
          if (rdoPrimary.SelectedIndex != -1)
          {
              Session["rdoPrimary"] = (string)rdoPrimary.SelectedValue;
  
          }
  
      }
  </code></pre>
  
  <p>Here is example of user code: </p>
  
  <p>THIS CODE NEVER FIRES BECAUSE the 3rd Button List data is not available here : </p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
      {
          /////*
          //// *  lab &amp; Primary have been selected... 
          //// */
          int lvl = SetLvlId();
          int par_id = GetParentLvl();
          Lab wuc = GetWuc(lvl);
          if (wuc != null)
          {
              if (CommonUI.strTest(Convert.ToString(Session["rdoLabs"])) &amp;&amp; CommonUI.strTest(Convert.ToString(Session["rdoPrimary"]))) 
              { 
                      // data in data base for this user, lab, doc identifier...
                      if (Convert.ToInt32(Session["rdoPrimary"]) &gt; 0
                       {
                          // have user hdr data - see if item data is mapped...
                         // do some stuff here
                      }
  
              } 
          }
      }
  </code></pre>
  
  <p>I hope this is clear.  I've att</p>
  
  <p>---<em>*</em>--- Since original posting: 
  added simple javascript/OnDataBound 
   function Primary(object)
      {
         alert("Value Clicked :" + object);
      }</p>
  
  <p>
                                                          
                                                          <br>
                                                          
                                                      
                                                      </p>
  
  <p>protected void rdoPrimary_DataBound(object sender, EventArgs e)
      {
          RadioButtonList rdlPrimary = (RadioButtonList)sender;
          foreach (ListItem li in rdlPrimary.Items)
          {
              li.Attributes.Add("onclick", "javascript:Primary('" + li.Value + "')");
          }
      }</p>