I'm having a little trouble with my program. I'm currently programming a friend request script and basically when the user receives a friend request, it will automatically add it to a FlowLayoutPanel
and in each friend request, the user's name will show along with a accept and reject button. Here's the code:
foreach (object request in i.ToString())
{
Label userName = new Label();
Button accept = new Button();
Button reject = new Button();
accept.Click += Accept_Click;
reject.Click += Reject_Click;
userName.Text = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(dr["UserFirstName"].ToString() + " " + dr["UserLastName"].ToString());
accept.Text = "Accept";
reject.Text = "Reject";
friendRequestPanel.Controls.Add(userName);
friendRequestPanel.Controls.Add(accept);
friendRequestPanel.Controls.Add(reject);
}
Now the problem is, when the user either accepts or rejects a request, it seems to delete all of the labels and buttons. Code:
friendRequestPanel.Controls.Remove(UserName); // Label
friendRequestPanel.Controls.Remove(accept); // Button
friendRequestPanel.Controls.Remove(rejects); // Button
How would I assign an id to each button and label so I can remove it later on?
Something like: friendRequestPanel.Controls.Remove(username[ID No]);