protected void FvDriverView_CallInsertOrUpdate(string CallCommand) { string currentUserID = User.Identity.GetUserId(); // Code versions of all controls TextBox txtForename = (TextBox)FvDriverView.FindControl("txtForename"); TextBox txtSurname = (TextBox)FvDriverView.FindControl("txtSurname"); TextBox txtDateOfBirth = (TextBox)FvDriverView.FindControl("txtDateOfBirth"); TextBox txtAddress1 = (TextBox)FvDriverView.FindControl("txtAddress1"); TextBox txtAddress2 = (TextBox)FvDriverView.FindControl("txtAddress2"); TextBox txtCity = (TextBox)FvDriverView.FindControl("txtCity"); TextBox txtCounty = (TextBox)FvDriverView.FindControl("txtCounty"); TextBox txtPostCode = (TextBox)FvDriverView.FindControl("txtPostCode"); // Assign all text properties of controls to variables // Or skip this and assign straight into INSERT/UPDATE parameters string forename = txtForename.Text; string surname = txtSurname.Text; string dateofbirth = txtDateOfBirth.Text; string address1 = txtAddress1.Text; string address2 = txtAddress2.Text; string city = txtCity.Text; string county = txtCounty.Text; string postCode = txtPostCode.Text; DriversTableAdapter DriverAdapter = new DriversTableAdapter(); try { if (CallCommand == "Update") { // Conduct Update DriverAdapter.UpdateRecord(forename, surname, dateofbirth, address1, address2, city, county, postCode, currentUserID); //Response.Write("<script LANGUAGE='JavaScript' >alert('Record Edited')</script>"); ClientScript.RegisterStartupScript(GetType(), "text", "AlertTimeout();", true); // Return to Read Only mode FvDriverView.ChangeMode(FormViewMode.ReadOnly); PageDataRefresh(); } else if (CallCommand == "Insert") { // Perform INSERT DriverAdapter.InsertRecord(currentUserID, forename, surname, dateofbirth, address1, address2, city, county, postCode); // Display message to user //Response.Write("<script LANGUAGE='JavaScript' >alert('Record Added')</script>"); ClientScript.RegisterStartupScript(GetType(), "text", "AlertTimeout();", true); // Redirect User FvDriverView.ChangeMode(FormViewMode.ReadOnly); } } catch (System.Exception ex) { Response.Write("<script LANGUAGE='JavaScript' >alert('An ERROR occurred connecting to the database. " + ex.Message + "')</script>"); } }