I've had issues like this before. I fixed them by:
- When you instantiate your usercontrol before you put it into the
placeholder it needs to have the same ID as it did before postback
(ie when you first created it). I do something like
"usr_" + <db
record id>
. This ensures its the same ID no matter what order it
gets loaded, what records get deleted, etc. This is probably the most
important thing to do, because if you don't assign it ID's .NET will
assign them for you -- and they are assigned in the order they show
up in the control collection which means you potentially will have
the wrong info in the wrong user control (which you described in your
question).
- Not using the session to store info about the page. Once the ID
issues were fixed people were still having issues if the opened up
two tabs of the same page.
Something along these lines:
using (SqlConnection c = new SqlConnection(DB_STRING))
{
c.Open();
String sql = @"
SELECT *
FROM yourTable
ORDER BY ID;";
using (SqlCommand cmd = new SqlCommand(sql, c))
{
using (SqlDataReader d = cmd.ExecuteReader())
{
while (d.Read())
{
UserControl uc = (UserControl)new UserControl().LoadControl("~/path/to-your-control/YourControl.ascx");
uc.ID = "usr_" + d["ID"];
plcHolderRows.Controls.Add(uc);
}
}
}
}