title: Delete element from div in div with a button generated from code behind
body: <p>I have an asp.net application with a page where users can post messages on. These messages are retrieved from the database in which they are stored on forehand in my pageload section in code behind. For each message a new div is generated with in there another div for the message and one for the username. A button is made for each individual post, and the problem is that I want the button to remove a post (thus the message in the database) from the div. But I can't figure out how to do it since everything is generated in code behind. Maybe FindControl() can help?</p>
  
  <pre><code>String connString = System.Configuration.ConfigurationManager.ConnectionStrings["WebAppConnString"].ToString();
              conn = new MySqlConnection(connString);               
              conn.Open();
              queryStr = "SELECT berichtID ,bericht, user FROM tblforum ORDER BY berichtID DESC";
              cmd = new MySqlCommand(queryStr, conn);
              MySqlDataReader Reader = cmd.ExecuteReader();
          try {
              while (Reader.Read())
              {
                  ImageButton Button = new ImageButton();
                  Button.ImageUrl = "https://cdn4.iconfinder.com/data/icons/ionicons/512/icon-ios7-gear-512.png";
                  HtmlGenericControl User = new HtmlGenericControl("div");
                  HtmlGenericControl Div = new HtmlGenericControl("div");
                  HtmlGenericControl Username = new HtmlGenericControl("p");
                  HtmlGenericControl Message = new HtmlGenericControl("p");
                  Button.Style.Add("max-height", "inherit");
                  Button.Style.Add("width", "auto");
                  Button.Style.Add("float", "right");
                  Username.InnerText = Reader["user"].ToString() + " said: ";
                  Div.Style.Add("border-bottom", "6px solid black");
                  Div.Style.Add("background-color", "#006633");
                  Message.Style.Add("color", "#d3d3d3");
                  forumsection.Controls.Add(Div);
                  Message.InnerText = Reader["bericht"].ToString();
                  Div.Controls.Add(User);
                  User.Controls.Add(Button);
                  User.Controls.Add(Username);
                  Div.Controls.Add(Message);
              }
              Reader.Close();
          }
  </code></pre>
  
  <p>Thank you</p>