javascript with if statment to fire buttons in code behind asp.net c#
<p>i am adding products in gridview and a im checking if the las record exist in list i have a messege to update the existed record or delete the last inserted! Below is my code but it does not work! can anyone help me?</p>

<pre><code>public void SaveToList()
        {
            try
            {
                OrdersDataContext contex = DataContextSingleton.Instance;

                _order = new Order();
                _order.quant = Int32.Parse(quant.Text);
                _order.price = price.Text;
                _order.totalprice = Decimal.Parse(totprice.Text);
                _order.discoun_id = Int32.Parse(TextBox3.Text);
                _order.prod_id = Int32.Parse(TextBox2.Text);
                _order.regist_id = Int32.Parse(TextBox4.Text);

                _readyToSave.Add(_order);
                //contex.Orders.InsertOnSubmit(ord);
                //contex.SubmitChanges();
                if (_readyToSave.Count() != 0)
                {
                    var selectO = (from o in _readyToSave
                                   orderby o.prod_id
                                   select new
                                   {
                                       val1 = o.prod_id
                                   }).Last();

                    TextBox15.Text = selectO.val1.ToString();

                    var selectpr = from p in _readyToSave
                                   where (p.prod_id == Int32.Parse(TextBox15.Text))
                                   select p;
                    if (selectpr.Count() &gt; 0)
                    {
                        btnAdd.Attributes.Add("onclick", "var agree=confirm('This product exist on you order! Do you want to update it???'); if (agree){document.getElementById('&lt;%= btnUpdate%&gt;').click();} else{document.getElementById('&lt;%= btnDelNew %&gt;' ).click();}");
                        //Response.Write("&lt;script language='javascript'&gt;alert('This product already have been added in list!!!')&lt;/script&gt;");
                    }
                }

                ClearTheFields();
                Sum();
            }
            catch
            {
            }

        }
</code></pre>

<hr>

<p>don't know why but it stops working, doesn't call button.. btnAdd.Attributes.Add("onclick", "var agree=confirm('This product exists on you order! Do you want to update it???'); if (agree){document.getElementById('" + btnUpdate.ClientID + "').click();} else{document.getElementById('" + btnDelNew.ClientID + "' ).click();}"); can anyone help me???</p>
