2

In my code, how can i make it possible to show a alert box popping out ? i tried to replay throws new argument exception and add in Response.Write("alert('NOT Successful');"); but it shows that i have syntax error near")". Please help me if you know .thanks in an advance .

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

        }
    }
Dnyanesh
  • 2,265
  • 3
  • 20
  • 17
Ng Jing
  • 41
  • 7

2 Answers2

1

Use RegisterStartUpScript to add javascript to your page

string message = "alert('NOT Successful');";
 this.ClientScript.RegisterStartupScript(this.GetType(),"myAlert",message,true);
shreesha
  • 1,811
  • 2
  • 21
  • 30
0

can you please try the below code snippet, If you are having issue with syntax in Response.Write:

Response.Write(@"<script language='javascript'>alert('The following errors have occurred: \n" + strErrorDesc + " .');</script>");

Else please provide the complete code snippet.

Varun
  • 597
  • 7
  • 26