I have an details view that is attached to a sql datasource. When a new workorder is inserted i am sending an email. Right now there is some issue with my program and the user is not able to insert the data from my application but the email still gets send assuming the data is inserted.

This is my Details View Inserted Method:

        protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
    {
      if (successfull == true && Page.IsValid)
    {
    //TextBox TextBoxWorkOrderNumber = (TextBox)(DetailsView1.FindControl("TextBox11"));
      TextBox TextBoxRequestor = (TextBox)(DetailsView1.FindControl("TextBox3"));
    TextBox TextBoxDate = (TextBox)(DetailsView1.FindControl("TextBox1"));
     //TextBoxDate.Text = DateTime.Now.ToShortDateString();
    TextBox TextBoxDepartment = (TextBox)(DetailsView1.FindControl("TextBox4"));
    TextBox TextBoxCompletionDate = (TextBox)(DetailsView1.FindControl("TextBox16"));
    TextBox TextBoxMachineDescription = (TextBox)(DetailsView1.FindControl("TextBox5"));
      TextBox TextBoxMachineLocation = (TextBox)(DetailsView1.FindControl("TextBox6"));
      TextBox TextBoxWorkRequired = (TextBox)(DetailsView1.FindControl("TextBox7"));
     // DropDownList status = (DropDownList)(DetailsView1.FindControl("DropDownList2"));
      TextBox TextBoxStatus = (TextBox)(DetailsView1.FindControl("TextBox12"));
      TextBoxStatus.Text = "Open";
    DropDownList list = (DropDownList)(DetailsView1.FindControl("DropDownList1"));
      TextBox9.Text = list.SelectedValue;
       DropDownList lists = (DropDownList)(DetailsView1.FindControl("DropDownList2"));
       TextBox14.Text = lists.SelectedValue;

     if (TextBoxRequestor.Text.Length <= 0)
       {
      TextBoxRequestor.Text = "Not Applicable";
       }
      if (TextBox14.Text.Length <= 0)
       {
      TextBoxDepartment.Text = "Not Provided";
      }
      if (TextBoxCompletionDate.Text.Length <= 0)
      {
      TextBoxCompletionDate.Text = "Not Provided";
      }
      if (TextBoxMachineDescription.Text.Length <= 0)
      {
      TextBoxMachineDescription.Text = "Not Provided";
      }
    if (TextBoxMachineLocation.Text.Length <= 0)
      {
      TextBoxMachineLocation.Text = "Not Provided";
      }
    if (TextBoxWorkRequired.Text.Length <= 0)
      {
        TextBoxWorkRequired.Text = "Not Provided";
      }
     if (TextBox9.Text == "Safety")
       {
      {
      bool isLocal = HttpContext.Current.Request.IsLocal;
     if (isLocal == true)
      {
       string id = TextBox13.Text.ToString();
       System.Net.Mail.MailMessage mm = new System.Net.Mail.MailMessage();
     mm.From = new System.Net.Mail.MailAddress("no_reply_workorder@.com");//who send
       mm.To.Add(new System.Net.Mail.MailAddress("abc@.com"));
    //abc@abc.com
    mm.Subject = "WorkOrders Type Safety";
    mm.Body = "DO NOT REPLY TO THIS EMAIL" + "<br><br/>" + "WorkOrderNumber" 
+ ": &nbsp;" + "<a href=\"http://localhost:49695/SafetyReport.aspx?WorkOrderNum=" + TextBox13.Text + "\">"
 + TextBox13.Text + "</a>" + "<-Click on the Work Order Number For Report"
 + "<br><br/>" + "WorkOrderNumber" + ": &nbsp;" + 
"<a href=\"http://localhost:49695/Safety.aspx?WorkOrderNum=" + 
TextBox13.Text + "\">" + TextBox13.Text + "</a>" +
 "<-Click on this Work Order Number To Enter Data" + 
"<br><br/>" + "Requestor" + ":&nbsp;" + TextBoxRequestor.Text +
 "<br><br/>" + "Date" + ":&nbsp;" + TextBoxDate.Text + 
"<br><br/>" + "Department" + ":&nbsp;" + TextBox14.Text +
 "<br><br/>" + "Machine Description" + ":&nbsp;" + 
TextBoxMachineDescription.Text + "<br><br/>" + 
"Machine Location" + ":&nbsp;" + 
TextBoxMachineLocation.Text + "<br><br/>" +
 "Work Required" + 
       mm.IsBodyHtml = true;
       System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
       client.Host = ConfigurationManager.AppSettings["smtpServer"];
       client.Send(mm);
       captureuseremail();
      }

    mm.IsBodyHtml = true;
     System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
     client.Host = ConfigurationManager.AppSettings["smtpServer"];
     client.Send(mm);
    captureuseremail();
     } 

i see an DetailsView1_Item Inserting how can i check if that is inserting into the sql database?? if the inserting is successful i like to set a boolean value to true and if true then perform the Details_View1 Inserted and send email else cancel the insert.

i am also using the insert button that comes with the details view. please ask me for additional code if your confused and i would more than happily provide it.

please help :(

Related posts

Recent Viewed