title: Accessing dynamically created html elements from c# code behind
body: <p>I am dynamically generating radio buttons for a list of questions, each question has at least 3 choices as answers.
  I generated the radio buttons in a div called <code>questionsList</code> but I can't access them or their fieldset...
  Here's my code</p>
  
  <pre><code>      _questions = Page.Form.FindControl("questionsList");
  
              foreach (Question q in _survey.Questions)
              {
                  if (!string.IsNullOrEmpty(q.QuestionEng))
                  {
                      List&lt;Answers&gt; answers = _blSurvey.GetAnswers(q.TypeOfQuestion);
                      string choiceItem = string.Empty;
                      foreach (Answers a in answers)
                      {
                          choiceItem += "&lt;input type='radio' value='" + a.AnswerId + q.QuestionId +
                                        "' name='radio-choice-v-2' id='radio" + idCount +
                                        "' runat='server' /&gt;&lt;label for='radio" + idCount++ +
                                        "' &gt;" + a.AnswerEng + "&lt;/label&gt;";
                      }
                      var question =
                          new LiteralControl(
                              "&lt;form&gt;&lt;fieldset runat='server' class='questions' data-role='controlgroup' ID ='question" +
                              q.QuestionId + "'&gt;" +
                              "&lt;legend runat='server'&gt;" + ++index + ". " + q.QuestionEng + "&lt;/legend&gt;" + choiceItem +
                              "&lt;/fieldset&gt;&lt;/form&gt;");
  
                      _questions.Controls.Add(question);
                  }
              }
  </code></pre>
  
  <p>I tried to use <code>FindControl()</code> with the string question and the question's id since it is the IS I specified for the fieldset (<code>ID ='question" + q.QuestionId</code>) but it didn't work,
  I also tried to access any of the dynamically generated controls but I always get null.
  If my way of generating controls is incorrect, please tell me what is the best method to do so I am very new to asp.net. Thanks in advance. </p>