title: ASP.net 2.0 dynamic Radio Button
body: <p>I need to create dynamic radio buttons in my page, and then access their values in postback</p>
  
  <p>I create the buttons using the following code:</p>
  
  <pre><code>foreach (Answer answer in question.Answers)
  {
      RadioButton radioButton = new RadioButton();
      radioButton.Text = answer.Text;
      radioButton.GroupName = question.Id.ToString();
      radioButton.ID = question.Id + "_" + answer.Id;
  
      TableRow answerRow = new TableRow();
      TableCell answerCell = new TableCell();
      TableCell emptyCell = new TableCell();
  
      emptyCell.ColumnSpan = 2;
  
      answerCell.Controls.Add(radioButton);
      answerRow.Cells.Add(emptyCell);
      answerRow.Cells.Add(answerCell);
  
      table.Rows.Add(answerRow);
  }
  </code></pre>
  
  <p>In the post back I try to access the radio buttons using their create ID:</p>
  
  <pre><code>foreach (Answer answer in question.Answers)
  {
      RadioButton currentAnswer = Page.FindControl(question.Id + "_" + answer.Id) as RadioButton;
      if (currentAnswer != null) // Damn this null
      {
          if(currentAnswer.Checked)
          {
              answers[questionCounter] = answer;
          }
      }
      else
      {
          allQuestionsAnswered = false;
      }
  }
  </code></pre>
  
  <p>But it seems that the find method is never finding the answer.</p>
  
  <p>Please let me know when to use the above code.
  In the load method, in the preload, in the button click of the submit method.</p>
  
  <p>It seems that I always get null and never find the control.</p>