2016-12-14 148 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();

  }