protected void UpdateButton_Click(object sender, EventArgs e) { int DepID = (int)HttpContext.Current.Session["DeptID"]; int NewEmployeeID = Convert.ToInt32(URDropDownList.SelectedValue); //changed from CPRadioButtonList to URDropDownList int OldEmployeeID = Convert.ToInt32(SupplierBizLogic.FindCollectionByDepID(DepID).EmployeeID); UserRepCollection updatedDeptURCollection = new UserRepCollection { }; // must declare a variable here first before using it in try block or else not detectable try { SupplierBizLogic.UpdateNewURinEmptable(NewEmployeeID); SupplierBizLogic.UpdateOldURinEmptable(OldEmployeeID); updatedDeptURCollection = SupplierBizLogic.UpdateURcollectiontableUR(DepID, NewEmployeeID); Response.Write("<script>alert('User Representative changed!');</script>"); } catch (Exception exp) { Response.Write(exp.ToString()); } // added code below: try { String from = "*****@*****.**"; List <String> toAddress = MailBizLogic.ClerkEmail(); String subject = String.Format("[Auto Notification] Changes on User Representative for {0}", updatedDeptURCollection.Department.Description); String body = String.Format("New User Representative For '{0}' has been assigned to {1}." + "\n\nNote: This is an auto-generated email. Please do not reply to this email." + "\n\nThis email is confidential and may be privileged.If you are not the intended recipient, " + "please delete it and notify us immediately; you should not copy or use it for any purpose, " + "nor disclose its contents to any other person.\n\nThank you.", updatedDeptURCollection.Department.Description, updatedDeptURCollection.Employee.Name); foreach (String to in toAddress) { MailBizLogic.sendMail(from, to, subject, body); } Label2.Text = SupplierBizLogic.FindCollectionByDepID(DepID).EmployeeName.ToString(); } catch (Exception ex) { Response.Write("Could not send the e-mail - error: " + ex.Message); } }