protected void btnSubmit_Click(object sender, EventArgs e) { InventoryItem updateItem = new InventoryItem(); if (hidInventoryId.Value != null && hidInventoryId.Value != "") { updateItem.setInventoryId(Convert.ToInt32(hidInventoryId.Value)); setUpdateItem(updateItem); if (ImageFileUpload.HasFile) { if (ImageFileUpload.PostedFile.ContentType == "image/jpeg" || ImageFileUpload.PostedFile.ContentType == "image/png") { String filename = Path.GetFileName(ImageFileUpload.FileName); ImageFileUpload.SaveAs(Server.MapPath("~/Graphics/" + filename)); updateItem.setImageUrl(ImageFileUpload.FileName); } } else { updateItem.setImageUrl(hidImagePath.Value); } sendItemToDb(updateItem); } else { setUpdateItem(updateItem); if (ImageFileUpload.HasFile) { if (ImageFileUpload.PostedFile.ContentType == "image/jpeg" || ImageFileUpload.PostedFile.ContentType == "image/png") { String filename = Path.GetFileName(ImageFileUpload.FileName); ImageFileUpload.SaveAs(Server.MapPath("~/Graphics/" + filename)); updateItem.setImageUrl(ImageFileUpload.FileName); } else { lblMsg.Text = "There is a problem with your image. It must be .jpg or .png. Please try again."; } sendNewItemToDb(updateItem); } else { lblMsg.Text = "An image file is required, please try again."; } } }