脚本消息未显示

时间:2016-12-14 08:15:51

标签: clientscript

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

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

1 个答案:

答案 0 :(得分:0)

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

更新部分:

  

捕                   {                       Console.WriteLine("插入失败");                       //Console.Read();

            }