0

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?

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() > 0)
                    {
                        btnAdd.Attributes.Add("onclick", "var agree=confirm('This product exist on you order! Do you want to update it???'); if (agree){document.getElementById('<%= btnUpdate%>').click();} else{document.getElementById('<%= btnDelNew %>' ).click();}");
                        //Response.Write("<script language='javascript'>alert('This product already have been added in list!!!')</script>");
                    }
                }

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

        }

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???

3 Answers 3

1

try with the ClientId property

btnAdd.Attributes.Add("onclick", "var agree=confirm('This product exist on you order! Do you want to update it???'); if (agree){document.getElementById('<%= btnUpdate.ClientId%>').click();} else{document.getElementById('<%= btnDelNew.ClientId %>' ).click();}");
Sign up to request clarification or add additional context in comments.

1 Comment

Please excuse the question: I have limited knowledge of the GridView, but will having the literal <%=btnUpdate.ClientId%> within the attribute of a button be automatically parsed as ctr001_btnUpdate (for example)? My gut feeling is that it will simply be sent to the brower as literally just <%=btnUpdate.ClientID%>
0

You have the button names defined as <%= btnUpdate%> and <%= btnDelNew %>. They should be defined as <%= btnUpdate.ClientID %> and <%= btnDelNew.ClientID %>.

UPDATE: If freefaller's gut feeling is correct (I haven't tested the above), then add the onclick attribute as the following:

btnAdd.Attributes.Add("onclick", "var agree=confirm('This product exist on you order! Do you want to update it???'); if (agree){document.getElementById('" + btnUpdate.ClientID + "').click();} else{document.getElementById('" + btnDelNew.ClientID + "' ).click();}");

1 Comment

Please excuse the question: I have limited knowledge of the GridView, but will having the literal <%=btnUpdate.ClientId%> within the attribute of a button be automatically parsed as ctr001_btnUpdate (for example)? My gut feeling is that it will simply be sent to the brower as literally just <%=btnUpdate.ClientID%>
0

I'm answering this without a real knowledge of GridViews, but my gut feeling is that you're literally sending the text <%=btnUpdate%> (or <%=btnUpdate.ClientID%>) to the browser.

What I think you need to do is change the line starting with...

btnAdd.Attributes.Add("onclick"...

To...

btnAdd.Attributes.Add("onclick", "var agree=confirm('This product exist on you order! Do you want to update it???'); if (agree){document.getElementById('" + btnUpdate.ClientID + "').click();} else{document.getElementById('" + btnDelNew.ClientID + "' ).click();}");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.