简体   繁体   English

在Asp.net应用程序上引发警报消息不起作用

[英]Throw Alert Message on Asp.net Application not working

I am trying to query against a database and retrieve one row of data then if data exist program continue if not I would like for an alert message to pop up the below code should work, I am not sure what happened after the rebuild the application runs the alert message code just as it were a normal program and does not display the message and no error occurs, I want the alert to popup and when the user clicks ok on the alert focus on the item textbox. 我正在尝试查询数据库并检索一行数据,然后如果数据存在,请继续运行程序(如果不存在),我希望弹出一条警报消息,以下代码应能正常工作,我不确定重建应用程序运行后发生了什么警报消息代码与正常程序一样,不显示消息且没有错误发生,我希望警报弹出,并且当用户在项目文本框上的警报焦点上单击“确定”时。 please help below is the code I am using: 请在下面帮助我正在使用的代码:

 try
 {

 var connectionstring = ConfigurationManager.ConnectionStrings["TestDataTable"].ConnectionString;
 OdbcConnection con = new OdbcConnection(connectionstring);
 //con.ConnectionString = connectionstring;
 if (TxtItem.Text != hold_item)
 {
 con.Open();
 OdbcCommand cmd = new OdbcCommand("Select t_item,t_idsc,t_upct,t_item_upc,t_ctyp,t_citg,t_best,t_disp,t_mold,t_csel " + "from informix.tsckcm907 " + "where t_item = " + stitem, con);

 OdbcDataReader myReader = cmd.ExecuteReader();
 DataTable testdt = new DataTable();

 testdt.Load(myReader);
 if (testdt.Rows.Count > 0)
 {
 {
 foreach (DataRow row in testdt.Rows)
 {
 lbldesc.Text = row["t_idsc"].ToString();
 lbldesc.Visible = true;


 Spanish_Item();
 if (hold_lang_value == 0)
 {
 TxtBestBeforeMonths.Text = row["t_best"].ToString();
 holdbest = Convert.ToInt16(TxtBestBeforeMonths.Text);
 }
 else
 {
 DropDownList2.SelectedIndex = 1;
 object stlanguage = 1;
 hold_language = Convert.ToString(stlanguage);
 TxtBestBeforeMonths.Text = row["t_best"].ToString();
 holdbest = Convert.ToInt16(TxtBestBeforeMonths.Text);
 }
 }
 }




 myReader.Close();
 myReader.Dispose();
 cmd.Dispose();
 con.Close();
 con.Dispose();
 }
 else
 {
 string message = "Item Not Found";
 System.Text.StringBuilder sb = new System.Text.StringBuilder();
 sb.Append("<script type = 'text/javascript'>");
 sb.Append("window.onload=function(){");
 sb.Append("alert('");
 sb.Append(message);
 sb.Append("')};");
 sb.Append("</script>");
 ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", sb.ToString()); ;
 TxtItem.Focus();

 }
 }  

so this is what fixed my issue above, 所以这就是解决我上面的问题的原因,

I had to use a bool to stop the program from continuing on and throw the error 我不得不使用布尔值来阻止程序继续运行并抛出错误

 else
    {
     string strErrorDesc = "Item Not Found";
     Response.Write(@"<script language='javascript'>
alert('The following errors have occurred: \n" + strErrorDesc + " .');</script>");
    value = false;
    }
    if (value == false)
    {

    }
    else
    {
    Calc_Rotation();
    Calc_Best_Before();
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM