在我的代码中,如何才能显示弹出警告框?我试图重播抛出新的参数异常并添加到Response.Write(" alert(' NOT Successful');"); 但它表明我在")"附近有语法错误。如果你知道的话,请帮助我。谢谢你。
if (!IsPostBack)
{
if (Page.Request.QueryString["hasProducts"].Equals("true"))
{
ArrayList al = Session["SelectedProducts"] as ArrayList;
if (al == null)
throw new ArgumentException("A product list is required.");
if (al.Count < 1)
throw new ArgumentException("No products selected");
string inStatement = string.Empty;
int len = al.Count;
int count = 1;
foreach (string item in al)
{
inStatement = inStatement + "'" + item + "'";
if (count < len) { inStatement = inStatement + ","; }
count++;
//List<string> list = new ArrayList<string>(item.Split(','));
//item.Split(',');
}
//List<String> list = new ArrayList<String>(al.split(","));
// inStatement = inStatement.Substring(0, inStatement.Length - 2);
//Product aProd = new Product();
SqlConnection con = new SqlConnection(strcon);
SqlCommand cmd = new SqlCommand("SELECT * FROM Products WHERE Product_ID in (" + inStatement + ")", con);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
con.Open();
adp.Fill(ds, "Products");
cmd.ExecuteNonQuery();
con.Close();
// GridView1.DataSource = ds;
//GridView1.DataBind();
DataList1.DataSource = ds;
DataList1.DataBind();
}
}
答案 0 :(得分:1)
使用RegisterStartUpScript向您的网页添加javascript
string message = "alert('NOT Successful');";
this.ClientScript.RegisterStartupScript(this.GetType(),"myAlert",message,true);
答案 1 :(得分:0)
如果您在Response.Write
中遇到语法问题,可以尝试下面的代码段吗?
Response.Write(@"<script language='javascript'>alert('The following errors have occurred: \n" + strErrorDesc + " .');</script>");
请提供完整的代码段。