在我的代码中,如何才能显示弹出的警告框?我尝试重放抛出新参数异常并添加Response.Write("alert('NOT Successful');");但它显示我在“)”附近有语法错误。如果你对.thanks有所了解,请帮助我。
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();
}
}发布于 2015-08-11 15:12:55
使用RegisterStartUpScript将javascript添加到页面
string message = "alert('NOT Successful');";
this.ClientScript.RegisterStartupScript(this.GetType(),"myAlert",message,true);发布于 2015-08-11 11:54:12
如果您在Response.Write中遇到语法问题,可以尝试下面的代码片段吗
Response.Write(@"<script language='javascript'>alert('The following errors have occurred: \n" + strErrorDesc + " .');</script>");否则,请提供完整的代码片段。
https://stackoverflow.com/questions/31932699
复制相似问题