protected void Page_Load(object sender, EventArgs e) { HttpCookie cookie = Request.Cookies["user_id"];//getting the user_id List <System.Web.UI.HtmlControls.HtmlGenericControl> element_list = new List <System.Web.UI.HtmlControls.HtmlGenericControl>(); if (cookie != null)//check if the cookie exists { //init the page builder PageElementGenerator peg = new PageElementGenerator(); //adding each cart breakout element to the page Process_Executor exec = new Process_Executor(); List <System.Web.UI.HtmlControls.HtmlGenericControl> all_prod_display = new List <System.Web.UI.HtmlControls.HtmlGenericControl>(); List <CART_INFORMATION> data_list = exec.retrieve_cart_data("not_his", cookie.Value); int i = 0; foreach (CART_INFORMATION data in data_list) { i++; //init the page builder PageElementGenerator pe1 = new PageElementGenerator(); maindiv.Controls.Add(pe1.generate_cart_summary_product_breakout(i, data)); } //retrieving and updating the cart summary section PlaceHolder1.Controls.Add(peg.generate_cart_summary(cookie.Value)); Total_Q.Text = peg.generate_cart_summary_total_quantity(cookie.Value); Total_Balance.Text = peg.generate_cart_summary_total_balance(cookie.Value); } }
//function that loads when the page is loading protected void Page_Load(object sender, EventArgs e) { HttpCookie cookie = Request.Cookies["user_id"];//getting the user_id List <System.Web.UI.HtmlControls.HtmlGenericControl> element_list = new List <System.Web.UI.HtmlControls.HtmlGenericControl>(); if (cookie != null)//check if the cookie exists { if (cookie.Value != "0") { //retrieving all the elements Process_Executor exec = new Process_Executor(); List <System.Web.UI.HtmlControls.HtmlGenericControl> all_prod_display = new List <System.Web.UI.HtmlControls.HtmlGenericControl>(); List <PRODUTCT_DATA> data_list = exec.retrieve_product("", cookie.Value); foreach (PRODUTCT_DATA data in data_list) { //the page builder PageElementGenerator peg = new PageElementGenerator(); //declaring default buttons Button add_button = peg.get_add_to_cart(); Button del_button = peg.get_delete_from_cart(); Button clear_button = new Button(); Button addq_button = peg.get_add_qauntity(); Button lessenq_button = peg.get_lessen_quantity(); //adding the respective events to the specific button addq_button.Click += new EventHandler(increased_quantity); lessenq_button.Click += new EventHandler(decreased_quantity); peg.set_add_qauntity(addq_button); peg.set_lessen_qauntity(lessenq_button); //adding the respective events to the specific button add_button.Click += new EventHandler(add_to_cart); peg.set_add_to_cart(add_button); maindiv.Controls.Add(peg.generate_product(data));//adding each product element to the list } } else { //getting page element the default way Process_Executor exec = new Process_Executor(); List <System.Web.UI.HtmlControls.HtmlGenericControl> all_prod_display = new List <System.Web.UI.HtmlControls.HtmlGenericControl>(); List <PRODUTCT_DATA> data_list = exec.retrieve_product("", ""); foreach (PRODUTCT_DATA data in data_list) { //the page builder PageElementGenerator peg = new PageElementGenerator(); Button addq_button = peg.get_add_qauntity(); Button lessenq_button = peg.get_lessen_quantity(); Button add_button = peg.get_add_to_cart(); //adding the respective events to the specific button add_button.Click += new EventHandler(login_transfer); //adding the respective events to the specific button addq_button.Click += new EventHandler(increased_quantity); lessenq_button.Click += new EventHandler(decreased_quantity); peg.set_add_qauntity(addq_button); peg.set_lessen_qauntity(lessenq_button); peg.set_add_to_cart(add_button); maindiv.Controls.Add(peg.generate_product(data));//adding each product element to the list } } } ////adding each element to the page //foreach(System.Web.UI.HtmlControls.HtmlGenericControl element in element_list) //{ // maindiv.Controls.Add(element); //} }