protected void postMessageButton_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(messageTextBox.Text)) { int messageId = Convert.ToInt32(Request.QueryString["MessageId"]); using (FlexibleTennisLeagueDataContext dataContext = new FlexibleTennisLeagueDataContext()) { dataContext.InsertMessageReply(messageId, StoredData.User.UserId, messageTextBox.Text); List <SelectRepliesResult> selectReplies = dataContext.SelectReplies(messageId).ToList(); messageRepeater.DataSource = selectReplies; messageRepeater.DataBind(); List <string> emailIds = new List <string>(); if (ViewState["PostOwnerEmail"] != null) { emailIds.Add(ViewState["PostOwnerEmail"].ToString()); } foreach (SelectRepliesResult result in selectReplies) { if (result.EmailPost.Value && !emailIds.Contains(result.EmailId)) { emailIds.Add(result.EmailId); } } StringBuilder sb = new StringBuilder(); string subject = string.Empty; if (ViewState["Subject"] != null) { sb.Append(string.Format("Following item was posted by {0} {1} as a reply to {2}", StoredData.User.FirstName, StoredData.User.LastName, ViewState["Subject"].ToString())); subject = "(FlexTennis)" + ViewState["Subject"].ToString(); } else { sb.Append("A recent post you have participated in has been updated."); subject = "(FlexTennis) Your post has been updated"; } sb.Append("\r\n\r\n-------------------------------------------------\r\n"); sb.Append(messageTextBox.Text); messageTextBox.Text = string.Empty; SendEmail(emailIds, sb, subject, StoredData.User.EmailId, StoredData.User.FirstName + " " + StoredData.User.LastName); } } }