簡體   English   中英

在Asp.net應用程序上引發警報消息不起作用

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

我正在嘗試查詢數據庫並檢索一行數據,然后如果數據存在,請繼續運行程序(如果不存在),我希望彈出一條警報消息,以下代碼應能正常工作,我不確定重建應用程序運行后發生了什么警報消息代碼與正常程序一樣,不顯示消息且沒有錯誤發生,我希望警報彈出,並且當用戶在項目文本框上的警報焦點上單擊“確定”時。 請在下面幫助我正在使用的代碼:

 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();

 }
 }  

所以這就是解決我上面的問題的原因,

我不得不使用布爾值來阻止程序繼續運行並拋出錯誤

 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