title: i need to get value on button click from dynamic control which was generated
body: <p>There have many controls are Generated I want to save value on button  click which is dynamically generated on page,Can any one Help me to this. I am new in this field so i m using many types of code from code but it cant ...</p>
  
  <pre><code> protected void Page_Load(object sender, EventArgs e)
         {
          if (!IsPostBack)
          {
              if (Request.QueryString["ID"] != null)
              {
  
                CreateDynamicForm(Convert.ToInt32(Request.QueryString["ID"]));
              }
          }
      }
  
      protected void CreateDynamicForm(int id)
      {
          DataTable dt = objDl.FetchList(id);
          if (dt.Rows.Count &gt; 0)
          {
              for (int i = 0; i &lt; dt.Rows.Count; i++)
              {
  
                  string text = Convert.ToString(dt.Rows[i]["ControlToDisplay"]);
                  string chkval = Convert.ToString(dt.Rows[i]["IsActive"]);
                  if (text == "Checkbox")
                  {
                      CheckBox chk = new CheckBox();
                      chk.ID = "Checkbox" + i;
                      string ID = chk.ID;
  
                      chk.Attributes["style"] = "margin-left: 87px;line-height: 3;";
                      if (chkval == "True")
                      {
                          chk.Checked = true;
                      }
                      else
                      {
                          chk.Checked = false;
                      }
  
                      Label lbl = new Label();
                      lbl.Text = Convert.ToString(dt.Rows[i]["FieldLabel"]);
  
                      panelDynamic.Controls.Add(lbl);
                      panelDynamic.Controls.Add(chk);
                      Literal lt = new Literal();
                      lt.Text = "&lt;br /&gt;";
                      panelDynamic.Controls.Add(lt);  
  
                      hdnID.Value = hdnID + "," + ID;
                      HdnType.Value = HdnType + "," + "Checkbox";
                  }
  
                  if (text == "Dropdownlist")
                  {
                      int j = 0;
                      DropDownList ddlList = new DropDownList();
                      ddlList.ID = "DdlDisplay" + i;
                      ddlList.CssClass = "form-group";
                     // ddlList.CssClass = "col-sm-3";
                      ddlList.Attributes["style"] = "margin-left: 96px;width: 151px;padding-left: 43px;";
                      string texts = Convert.ToString(dt.Rows[i]["OptionValue"]);
                      string[] txtcount = texts.Split(',');
                      foreach (var items in txtcount)
                      {
  
                          if (items.TrimStart().TrimEnd() != "")
                          {
                              j++;
                              ListItem ltm = new ListItem();
                              //ltm.Attributes["style"] = "padding-left: 43px;";
                              ltm.Value = "Listitem" + j;
                              ltm.Text = Convert.ToString(items);
  
                              //ddlList.Items.Add(txt);
                              ddlList.Items.Add(new ListItem(ltm.Text, ltm.Value));
  
                          }
                      }
  
                      hdnID.Value = hdnID + "," + ddlList.ID;
                      HdnType.Value = HdnType + "," + "Dropdownlist";
  
  
  
                      Label lbl = new Label();
                      lbl.Text = Convert.ToString(dt.Rows[i]["FieldLabel"]);
                      panelDynamic.Controls.Add(lbl);
  
                      panelDynamic.Controls.Add(ddlList);
  
                      Literal lt = new Literal();
                      lt.Text = "&lt;br /&gt;";
                      panelDynamic.Controls.Add(lt);
                  }
  
                  if (text == "SingleLineTextBox")
                  {
  
                      TextBox textb = new TextBox();
                      textb.ID = "TextBox" + i;
                      textb.Attributes["style"] = "margin-left: 87px;";
                      textb.Attributes["required"] = "true";
  
  
                      Label lbl = new Label();
                      lbl.Text = Convert.ToString(dt.Rows[i]["FieldLabel"]);
                      panelDynamic.Controls.Add(lbl);
  
                      panelDynamic.Controls.Add(textb);
  
                      Literal lt = new Literal();
                      lt.Text = "&lt;br /&gt;";
                      panelDynamic.Controls.Add(lt);
  
                      hdnID.Value = hdnID + "," + textb.ID;
                      HdnType.Value = HdnType + "," + "SingleLineTextBox";
                  }
  
                  if (text == "Multiline Textbox")
                  {
  
                      TextBox textMulti = new TextBox();
                      textMulti.ID = "MultiTextBox" + i;
                      textMulti.TextMode = TextBoxMode.MultiLine;
                      textMulti.Attributes["style"] = "margin-left: 87px;margin-top: 16px;";
                      textMulti.Attributes["required"] = "true";
  
                      Label lbl = new Label();
                      lbl.Text = Convert.ToString(dt.Rows[i]["FieldLabel"]);
                      panelDynamic.Controls.Add(lbl);
  
                      panelDynamic.Controls.Add(textMulti);
  
                      Literal lt = new Literal();
                      lt.Text = "&lt;br /&gt;";
                      panelDynamic.Controls.Add(lt);
  
                      hdnID.Value = hdnID + "," + textMulti.ID;
                      HdnType.Value = HdnType + "," + "Multiline Textbox";
  
                  }
  
                  if (text == "RadioButton")
                  {
                      RadioButton rdb = new RadioButton();
                      rdb.ID = "rdb" + i;
                      rdb.Attributes["style"] = "margin-left: 87px;line-height: 4";
  
                      Label lbl = new Label();
                      lbl.Text = Convert.ToString(dt.Rows[i]["FieldLabel"]);
                      panelDynamic.Controls.Add(lbl);
  
                      panelDynamic.Controls.Add(rdb);
  
                      Literal lt = new Literal();
                      lt.Text = "&lt;br /&gt;";
                      panelDynamic.Controls.Add(lt);
  
                      hdnID.Value = hdnID + "," + rdb.ID;
                      HdnType.Value = HdnType + "," + "RadioButton";
                  }
  
              }
          }
      }
  
      protected void btn_submit_Click(object sender, EventArgs e)
      {
  
      }
  </code></pre>