protected void Page_Load(object sender, EventArgs e) { int userid = (int)Session["userid"]; int user2 = (int)Session["msgid"]; DataTable convo = (DataTable)Session["convo"]; enter obj = new enter(); int rem = obj.UpdateLastSeen(userid, user2); heading.Text = obj.getName(user2); heading.Click += (se, ev) => { Session["uid"] = user2; Response.Redirect("user.aspx?val=" + user2); }; if (rem == -1) { msgtxt.Text = "An error occured. Please reload the page!"; } else { foreach (DataRow row in convo.Rows) { Label message = new Label(); message.ID = message.UniqueID; message.Text = row.Field <string>(1); message.Attributes.Add("style", "font-size: 20px;"); message.Attributes.Add("runat", "server"); Label time = new Label(); time.ID = time.UniqueID; time.Attributes.Add("style", "text-align: right;"); time.Text = "<sub>" + row.Field <DateTime>(2) + "</sub>"; if (row.Field <int>(0) == userid) { p.Controls.Add(new LiteralControl("<div style=\"border: solid; border-color: azure; background-color: rgba(18, 12, 85, 0.6); color: white; text-align: left \">")); } else { p.Controls.Add(new LiteralControl("<div style=\"border: solid; border-color: azure; background-color: rgba(255, 216, 0,0.6); color: white; text-align: right \">")); } p.Controls.Add(message); p.Controls.Add(new LiteralControl("<br/>")); p.Controls.Add(time); p.Controls.Add(new LiteralControl("</div>")); p.Controls.Add(new LiteralControl("<br/><br/>")); } } if (IsPostBack) { for (int i = ControlIds.Count - 1; i >= 0; i--) { Label message = new Label(); message.ID = "msg" + ControlIds[i]; message.Text = Texts[i]; message.Attributes.Add("style", "font-size: 20px;"); message.Attributes.Add("runat", "server"); Label time = new Label(); time.ID = "time" + ControlIds[i]; time.Attributes.Add("style", "text-align: right;"); time.Text = "<sub>" + Times[i] + "</sub>"; place.Controls.Add(new LiteralControl("<div style=\"border: solid; border-color: azure; background-color: rgba(18, 12, 85, 0.6); color: white; text-align: left \">")); place.Controls.Add(message); place.Controls.Add(new LiteralControl("<br/>")); place.Controls.Add(time); place.Controls.Add(new LiteralControl("</div>")); place.Controls.Add(new LiteralControl("<br/><br/>")); } } }