AndreMinDam
New Member
I created a new eventHandler for a new button. The old buttons saves the document. The new button I created is for when the user wants to update the content. However in my new eventHandler button, all the data fields are null or empty.in my Page_load I did this:\[code\]if (Request.QueryString["ExhibitID"] != null)//new{ if (!IsPostBack) { ddlCaseFiles.DataSourceID = "dsCaseFiles"; ddlCaseFiles.DataTextField = "Display"; ddlCaseFiles.DataValueField = "FileID"; rbByFileID.Checked = true; rbMyFiles.Checked = false; editExhibit(int.Parse(Request.QueryString["ExhibitID"]));//new exhibitHeader.InnerText = "Edit Exhibit"; } hidSavedExhibitID.Value = http://stackoverflow.com/questions/12588947/Request.QueryString["ExhibitID"]; saveExhibitBtn.Click += new EventHandler(this.btnUpdateExhibit_Click);}else{ saveExhibitBtn.Click += new EventHandler(this.saveExhibitBtn_Click);}\[/code\]so the save button works. But when I try to edit the page and press the update button, nothing will happen but an exception because all my fields are empty(even though they are filled out).Here are my methods for updating.editExhibit:\[code\] private void editExhibit(int expenseID)//new { saveExhibitBtn.Text = "Update Exhibit"; SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["OSCIDConnectionString"].ToString()); SqlCommand cmd = new SqlCommand("p_CaseFiles_Exhibits_RetrieveExhibitDetails", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ExhibitID", expenseID); bool hasAttachments = false; string investigatorID = ""; //bool alreadyInvoiced = false; bool isExpenseOwner = false; string fileID = "-1"; try { conn.Open(); var reader = cmd.ExecuteReader(); if (reader.HasRows) { reader.Read(); fileID = reader["FileID"].ToString(); ddlCaseFiles.SelectedValue = http://stackoverflow.com/questions/12588947/fileID; ddlCaseFiles.Enabled = false; // retrieve exhibit details here hasAttachments = (bool)reader["HasAttachments"]; //investigatorID = reader["InvestigatorID"].ToString(); if (Session["InvestigatorID"].ToString() == investigatorID) { isExpenseOwner = true; } txtDateReceived.Value = http://stackoverflow.com/questions/12588947/reader["SeizeDate"].ToString(); ddlReceivedBy.SelectedValue = http://stackoverflow.com/questions/12588947/reader["SeizedBy"].ToString(); txtTimeReceived.Value = http://stackoverflow.com/questions/12588947/reader["SeizeTime"].ToString(); txtWhyHowReceived.Value = http://stackoverflow.com/questions/12588947/reader["SzAuthority"].ToString(); txtReceivedLocation.Value = http://stackoverflow.com/questions/12588947/reader["Location"].ToString(); txtOurItemNum.Value = http://stackoverflow.com/questions/12588947/reader["ItemNumber"].ToString(); txtTheirItemNum.Value = http://stackoverflow.com/questions/12588947/reader["ClientItemNum"].ToString(); txtBagNum.Value = http://stackoverflow.com/questions/12588947/reader["BagNumber"].ToString(); txtBoxNum.Value = http://stackoverflow.com/questions/12588947/reader["BoxNumber"].ToString(); txtComment.Value = http://stackoverflow.com/questions/12588947/reader["ExhDesc"].ToString(); txtSerialNum.Value = http://stackoverflow.com/questions/12588947/reader["SerialNumber"].ToString(); ddlGrades.SelectedValue = http://stackoverflow.com/questions/12588947/reader["ItemEntryGradeID"].ToString();///iffy } } catch (SqlException ex) { ErrorLogger.Log(ex.Number, "NewExhibit.aspx - editExhibit - Retrieve Details", ex.Message); } catch (Exception ex) { ErrorLogger.Log(0, "NewExhibit.aspx - editExhibit - Retrieve Details", ex.Message); } finally { if (ConnectionState.Open == conn.State) conn.Close(); } #region "Get Attachments" if (hasAttachments) { hidTempHasAttachments.Value = "http://stackoverflow.com/questions/12588947/True"; SqlConnection cnGetAttachments = new SqlConnection(ConfigurationManager.ConnectionStrings["OSCIDConnectionString"].ToString()); SqlCommand comGetAttachments = new SqlCommand("p_CaseFiles_Exhibits_ListAttachmentsForExhibits", cnGetAttachments); comGetAttachments.CommandType = CommandType.StoredProcedure; comGetAttachments.Parameters.Add(new SqlParameter("@ExhibitID", SqlDbType.Int)); comGetAttachments.Parameters["@ExhibitID"].Value = http://stackoverflow.com/questions/12588947/int.Parse(Request.QueryString["ExhibitID"]); cnGetAttachments.Open(); try { SqlDataReader dra = comGetAttachments.ExecuteReader(); StringBuilder sbExistingAttachments = new StringBuilder(); while (dra.Read()) { bool fileAvailableForDownload = false; try { fileAvailableForDownload = (bool)dra["FileAvailableForDownload"]; } catch { fileAvailableForDownload = false; } if (fileAvailableForDownload) { sbExistingAttachments.Append("<a style='color:black;' href=http://stackoverflow.com/questions/12588947/DownloadFile.aspx?id=" + dra["BinaryFileID"].ToString() + "><img src='http://stackoverflow.com/questions/12588947/Images/DownloadFile.jpg' border='0' title='Download'></a>"); sbExistingAttachments.Append(dra["FileName"].ToString() + "<br>"); } else { sbExistingAttachments.Append("<img src='http://stackoverflow.com/questions/12588947/Images/DownloadFileNA.jpg' border='0' title='This file is still processing. And can not be downloaded at this time.'></a>"); sbExistingAttachments.Append(dra["FileName"].ToString() + "<br>"); } } cnGetAttachments.Close(); //lblFileAllreadyAttached.Text=sbExistingAttachments.ToString(); } catch (SqlException sqlEx) { ErrorLogger.Log(sqlEx.Number, "NewExhibit-Get Attachments", sqlEx.Message); if (cnGetAttachments.State == ConnectionState.Open) { cnGetAttachments.Close(); } } } #endregion //if(alreadyInvoiced) { // lblErrors.Text="This Expense has already been invoiced."; // DisableControls(); // return; //} //bool canEditExpeneses=InvestigatorDetails.CanEditExpenses((int)Session["InvestigatorID"]); //if(!canEditExpeneses&&!isExpenseOwner) { // DisableControls(); // lblErrors.Text="You do not have permissions to edit expenses."; // return; //} #region "Get Case File Status" if (fileID != "-1") { SqlCommand comGetFileStatus = new SqlCommand("select concluded from CaseFiles where FileID = " + fileID, conn); try { conn.Open(); string concluded = comGetFileStatus.ExecuteScalar().ToString(); if (concluded == "True") { DisableControls(); lblErrors.Text = "Cannot edit expense. The file is closed."; return; } } catch { } finally { if (conn.State == ConnectionState.Open) conn.Close(); } } #endregion }\[/code\]and here is my eventHandler for the updateBtn:\[code\] protected void btnUpdateExhibit_Click(object sender, EventArgs e) { hidSavedExhibitID.Value = "http://stackoverflow.com/questions/12588947/-1"; lblErrors.Text = ""; string[] BinaryFileIDs = retvalA.Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["OSCIDConnectionString"].ToString()); SqlCommand cmd = new SqlCommand("p_CaseFiles_Exhibits_UpdateExhibit", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@ExhibitID", SqlDbType.Int)).Value = http://stackoverflow.com/questions/12588947/int.Parse(Request.QueryString["ExhibitID"]); #region "Parameters" cmd.Parameters.Add(new SqlParameter("@FileID", SqlDbType.Int)).Value = http://stackoverflow.com/questions/12588947/int.Parse(ddlCaseFiles.SelectedValue); cmd.Parameters.Add(new SqlParameter("@InvestigatorID", SqlDbType.Int)).Value = http://stackoverflow.com/questions/12588947/(int)Session["InvestigatorID"]; cmd.Parameters.Add(new SqlParameter("@SeizeDate", SqlDbType.DateTime)).Value = http://stackoverflow.com/questions/12588947/txtDateReceived.Value.Trim(); cmd.Parameters.Add(new SqlParameter("@SeizeTime", SqlDbType.NVarChar, 4)).Value = http://stackoverflow.com/questions/12588947/txtTimeReceived.Value.Trim(); cmd.Parameters.Add(new SqlParameter("@SeizedByInvestigatorID", SqlDbType.Int)).Value = http://stackoverflow.com/questions/12588947/int.Parse(ddlReceivedBy.SelectedValue); cmd.Parameters.Add(new SqlParameter("@Location", SqlDbType.NVarChar, 500)).Value = http://stackoverflow.com/questions/12588947/txtReceivedLocation.Value.Trim(); cmd.Parameters.Add(new SqlParameter("@SeizeAuthority", SqlDbType.NVarChar, 500)).Value = http://stackoverflow.com/questions/12588947/txtWhyHowReceived.Value.Trim(); cmd.Parameters.Add(new SqlParameter("@BagNumber", SqlDbType.NVarChar, 128)).Value = http://stackoverflow.com/questions/12588947/txtBagNum.Value.Trim(); cmd.Parameters.Add(new SqlParameter("@BoxNumber", SqlDbType.NVarChar, 128)).Value = http://stackoverflow.com/questions/12588947/txtBoxNum.Value.Trim(); cmd.Parameters.Add(new SqlParameter("@ItemID", SqlDbType.Int)); cmd.Parameters.Add(new SqlParameter("@SubItemID1", SqlDbType.Int)); cmd.Parameters.Add(new SqlParameter("@SubItemID2", SqlDbType.Int)); cmd.Parameters.Add(new SqlParameter("@SubItemID3", SqlDbType.Int)); #region "Item Number" string[] fullItemNumber = txtOurItemNum.Value.Split('-');// this input gets stored as //"number-number-number-number". Hence the Split('-') because they get stored seperately in //the DB for (int x = 0; x < fullItemNumber.Length; x++) { switch (x) { case 0: cmd.Parameters["@ItemID"].Value = http://stackoverflow.com/questions/12588947/int.Parse(fullItemNumber[x].ToString()); break; case 1: cmd.Parameters["@SubItemID1"].Value = http://stackoverflow.com/questions/12588947/int.Parse(fullItemNumber[x].ToString()); break; case 2: cmd.Parameters["@SubItemID2"].Value = http://stackoverflow.com/questions/12588947/int.Parse(fullItemNumber[x].ToString()); break; case 3: cmd.Parameters["@SubItemID3"].Value = http://stackoverflow.com/questions/12588947/int.Parse(fullItemNumber[x].ToString()); break; } } #endregion cmd.Parameters.Add(new SqlParameter("@ClientItemNum", SqlDbType.NVarChar, 50)).Value = http://stackoverflow.com/questions/12588947/txtTheirItemNum.Value.Trim(); cmd.Parameters.Add(new SqlParameter("@ExhibitDescription", SqlDbType.NText)).Value = http://stackoverflow.com/questions/12588947/txtComment.Value.Trim(); cmd.Parameters.Add(new SqlParameter("@ExhibitDecriptionPlainText", SqlDbType.NText)).Value = http://stackoverflow.com/questions/12588947/txtComment.Value.Trim(); cmd.Parameters.Add(new SqlParameter("@Privileged", SqlDbType.Bit)).Value = http://stackoverflow.com/questions/12588947/0; cmd.Parameters.Add(new SqlParameter("@Private", SqlDbType.Bit)).Value = http://stackoverflow.com/questions/12588947/0; cmd.Parameters.Add(new SqlParameter("@HasAttachments", SqlDbType.Int)); if (BinaryFileIDs.Length > 0) cmd.Parameters["@HasAttachments"].Value = http://stackoverflow.com/questions/12588947/1; else cmd.Parameters["@HasAttachments"].Value = http://stackoverflow.com/questions/12588947/0; cmd.Parameters.Add(new SqlParameter("@ItemEntryGradeID", SqlDbType.Int)); if (ddlGrades.SelectedValue != "-1" && ddlGrades.SelectedValue != "") { cmd.Parameters["@ItemEntryGradeID"].Value = http://stackoverflow.com/questions/12588947/int.Parse(ddlGrades.SelectedValue); } else { cmd.Parameters["@ItemEntryGradeID"].Value = http://stackoverflow.com/questions/12588947/null; } cmd.Parameters.Add(new SqlParameter("@Success", SqlDbType.Int)).Direction = ParameterDirection.Output; cmd.Parameters.Add(new SqlParameter("@NewExhibitID", SqlDbType.Int)).Direction = ParameterDirection.Output; #endregion try { conn.Open(); cmd.ExecuteNonQuery(); //exhibitID = (int)cmd.Parameters["@ExhibitID"].Value; hidNewExhibitID.Value = http://stackoverflow.com/questions/12588947/hidSavedExhibitID.Value; lblErrors.Text ="Exhibit Updated."; } catch (SqlException sqlEx) { ErrorLogger.Log(sqlEx.Number, "NewExhibit.aspx-Save Exhibit", sqlEx.Message); hidSavedExhibitID.Value = "http://stackoverflow.com/questions/12588947/F"; } catch (Exception ex) { ErrorLogger.Log(0, "NewExhibit.aspx-Save Exhibit - non-sql error", ex.Message); hidSavedExhibitID.Value = "http://stackoverflow.com/questions/12588947/F"; } finally { if (ConnectionState.Open == conn.State) conn.Close(); } }\[/code\]