protected void btnXoa_Command(object sender, CommandEventArgs e) { try { int id = Int32.Parse(e.CommandArgument.ToString()); TourDLEntities db = new TourDLEntities(); QLTour.Contact obj = db.Contact.FirstOrDefault(x => x.ID_Contact == id); if (obj != null) { db.Contact.Remove(obj); db.SaveChanges(); getData(); } } catch { // } }
protected void btnSubmit_Click(object sender, EventArgs e) { try { TourDLEntities db = new TourDLEntities(); QLTour.Contact obj = new QLTour.Contact(); obj.Name = txtName.Text; obj.Email = txtEmail.Text; obj.Subject = txtSubject.Text; obj.Message = txtMessage.Text; db.Contact.Add(obj); db.SaveChanges(); //Response.Write("<script>alert('Gửi thành công!');</script>"); Response.Redirect("Contacts.aspx"); } catch (Exception) { // Lỗi Response.Write("<script>alert('Gửi thất bại!');</script>"); } }