2016-12-14 113 views
0

页脚本继续运行,不会显示消息“您的请求已成功提交”,如下面提到的。任何人都可以请帮助我在这里失踪?脚本消息不显示

protected void Button1_Click1(object sender, EventArgs e) 
{ 
    string constring = System.Configuration.ConfigurationManager.ConnectionStrings["GerpConnStr"].ConnectionString; 
    SqlConnection con = new SqlConnection(constring); 
    string name = System.Web.HttpContext.Current.User.Identity.Name; 
    string domain = name.Substring(+13); 
    try 
    { 
     con.Open(); 
     SqlCommand cmd = con.CreateCommand(); 
     SqlCommand cmd1 = new SqlCommand("SELECT max(ID) as maxReq FROM request", con); 
     cmd1.CommandType = CommandType.Text; 
     int result = ((int)cmd1.ExecuteScalar()); 
     int req = result + 1; 
     if (FileUpload1.HasFile) 
     { 
      string extension1 = Path.GetExtension(FileUpload1.PostedFile.FileName); 
      string attachment = (FileUpload1.FileName + '_' + req + extension1); 
      cmd.CommandType = CommandType.Text; 
      string dt2 = DateTime.Now.ToString("yyyyMMddHHmmss"); 
      DateTime time = DateTime.Now; 
      cmd.CommandText = "insert into request (request_type,request_area,subject,description,requestor,req_status,attachment,request_time) values('" + DropDownList1.SelectedValue + "','" + DropDownList2.SelectedValue + "','" + TextBox1.Text + "','" + TextArea1.InnerText + "','" + Label3.Text + "','" + "Open" + "','" + attachment + "','" + time + "')"; 

      string saveDir = @"\upload\" + Server.HtmlEncode(FileUpload1.FileName);   
      string dt = DateTime.Now.ToString("MM_dd_yyyy_hh_mm_ss") + "_"; 
      string appPath = Request.PhysicalApplicationPath; 
      string extension = Path.GetExtension(FileUpload1.PostedFile.FileName); 
      string savePath = appPath + saveDir + 
      Server.HtmlEncode(FileUpload1.FileName); 
      string saveSess = saveDir + dt + 
      Server.HtmlEncode(FileUpload1.FileName); 
      FileUpload1.SaveAs(saveDir + '_' + req + extension); 
      // Label4.Text = "Your request has been submitted successfully"; 
      string message = "Your request has been submitted successfully"; 
      string script = "window.onload = function(){ alert('"; 
      script += message; 
      script += "');"; 
      script += "window.location = '"; 
      script += Request.Url.AbsoluteUri; 
      script += "'; }"; 
      ClientScript.RegisterStartupScript(this.GetType(), "SuccessMessage", script, true); 
      Session["sessimage1"] = saveSess; 

      // CreateMailItem(); 
     } //if 
     else 
     { 

      // string extension1 = Path.GetExtension(FileUpload1.PostedFile.FileName); 
      // string attachment = (FileUpload1.FileName + '_' + req + extension1); 
      // SqlCommand cmd1 = con.CreateCommand(); 
      cmd.CommandType = CommandType.Text; 
      DateTime time = DateTime.Now; 
      // string dt1 = DateTime.Now.ToString("yyyyMMddHHmmss"); 
      cmd.CommandText = "insert into request (request_type,request_area,subject,description,requestor,req_status,request_time) values('" + DropDownList1.SelectedValue + "','" + DropDownList2.SelectedValue + "','" + TextBox1.Text + "','" + TextArea1.InnerText + "','" + Label3.Text + "','" + "Open" + "','" + time + "')"; 
      // Label4.Text = "Your request has been submitted successfully";    
      string message = "Your request has been submitted successfully"; 
      string script = "window.onload = function(){ alert('"; 
      script += message; 
      script += "');"; 
      script += "window.location = '"; 
      script += Request.Url.AbsoluteUri; 
      script += "'; }"; 
      ClientScript.RegisterStartupScript(this.GetType(), "SuccessMessage", script, true); 
      // Response.Redirect(Request.Url.AbsoluteUri); 

      // EmptyTextBoxes(TextBox1.Text); 
      // this.Controls.Clear(); 
      // this.InitializeComponent(); 

     } //else 

     // SaveFile(FileUpload1.PostedFile); 
     cmd.ExecuteNonQuery(); 
     cmd1.ExecuteNonQuery(); 
     con.Close();   
    } //try 
    catch 
    { 
     Console.WriteLine("Insert failed"); 
     Console.Read(); 
    } 
    finally 
    { 
     con.Close(); 
    } 
    CreateMailItem(); 
} //button1 
+0

请编辑您的代码块,并请更多内容添加到你的问题,因为没有解释,我们是无法修改的问题。 –

回答

0

现在就解决了。它在CreateMailItem()中的Console.Read()时出错。这就是为什么它永远不会回到Button1_Click1(对象发件人,EventArgs e)发布成功提交的消息。我省略了Console.Read(),现在CreateMailItem()的执行完成,控制返回到Button1_Click1(对象发送者,EventArgs e)发布成功提交的消息。

更新部分:

抓 { Console.WriteLine( “插入失败”); //Console.Read();

  }