protected void SaveNewCar_Click(object sender, EventArgs e) { string type = VehicleType.Text; string strYear = Convert.ToString(InjectYear.Text); string make = InjectMake.Text; string model = InjectModel.Text; string desc = VehicleDesc.Text; string valueCat = ValueRange.SelectedValue; string virtualPath = "~/Images/"; string physicalFolder = Server.MapPath(virtualPath); string fileName = Guid.NewGuid().ToString(); string extension = System.IO.Path.GetExtension(FileUpload1.FileName); string imgUrl = System.IO.Path.Combine(virtualPath, fileName + extension); int year = Convert.ToInt32(strYear); int miles = Convert.ToInt32(VehicleMiles.Text); UserClass uc = new UserClass(Profile.UserName); if (extension == ".jpg" || extension == ".jpeg") { FileUpload1.SaveAs(System.IO.Path.Combine(physicalFolder, fileName + extension)); CarClass cc = new CarClass(Profile.UserName); UserControl ucx = (UserControl)LoadControl("~/Controls/UserNoticeModal.ascx"); Label txtLabel = (Label)ucx.FindControl("TextLabel"); if (cc.AddCarToProfile(type, make, model, year, miles, desc, imgUrl, valueCat)) { txtLabel.Text = "Vehicle successfully added to your profile!"; Form.Controls.Add(ucx); } else { txtLabel.Text = "Sorry, an error occurred. Only 2 vehicles are allowed."; Form.Controls.Add(ucx); } } else { CustomValidator imgValidate = (CustomValidator)ImgValid; imgValidate.IsValid = false; } if (uc.UserIsValid()) { if (Profile.IsValidated != true) { Profile.IsValidated = true; Response.Redirect("~/MyProfile/MyProfile.aspx?isvalid=true"); } } else { if (Profile.IsValidated == true) { Profile.IsValidated = false; } } CarsGridView.DataSourceID = "CarsDataSource"; CarsGridView.DataBind(); }