c# - 抛出新的 ArgumentException

标签 c# asp.net throws

在我的代码中,我怎样才能显示弹出的警告框?我试图重播抛出新的参数异常并添加 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();

        }
    }

最佳答案

使用RegisterStartUpScript将 javascript 添加到您的页面

string message = "alert('NOT Successful');";
 this.ClientScript.RegisterStartupScript(this.GetType(),"myAlert",message,true);

关于c# - 抛出新的 ArgumentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31932699/

相关文章:

c# - 使用 C# 或 javascript 比较两个字符串数组

java - 在 Java 中捕获异常与抛出异常

c# - 在设计工具箱中找不到 ToolStripDropDownButton

C# 正则表达式检索层次字符串

c# - C# smtp.gmail.com 和端口号 587 中目标主机拒绝发送电子邮件

c# - 如何访问 ApiController 中的 Response

function - TypeScript 中错误抛出函数的签名

java - Java中 'throws'语句的用途是什么?

c# - 如何将对象转换为元组?

asp.net - 在 MySQL 中存储图片 - 聪明吗?