HTML dynamic nested form - one of two nested form not working?

scorpioan

New Member
I have a page which allows HTML markup for a PayPal Checkout Button to be pasted into a textbox. This is then saved, without any changes, in an SQL database...\[code\]protected void btnSubmit_Click(object sender, EventArgs e){ try { string query = "INSERT INTO Products VALUES ( @category, @name, @price, @buttoncode )"; using (SqlConnection conn = DatabaseUtility.getConn()) { SqlCommand cmd = new SqlCommand(query, conn); cmd.Parameters.AddWithValue("@category", ddlProductCategory.SelectedValue); cmd.Parameters.AddWithValue("@name", tbName.Text); cmd.Parameters.AddWithValue("@price", tbPrice.Text); cmd.Parameters.AddWithValue("@buttoncode", tbButtonCode.Text); conn.Open(); if (cmd.ExecuteNonQuery() == 1) { Response.Redirect(Request.RawUrl); } } } catch (Exception exc) { lblMsg.Text = "An error occured. Here is your error message: " + exc.Message + "<br /><br />" + exc.StackTrace; }}\[/code\]When the user visits the shop, this content is then pulled and displayed on the page. The PayPal button code is added to the page using a LiteralControl as seen below...\[code\]protected void Page_Load(object sender, EventArgs e){ try { string query = "SELECT * FROM Products WHERE Category = '" + getCategory() + "'"; using (SqlConnection conn = DatabaseUtility.getConn()) { SqlCommand cmd = new SqlCommand(query, conn); conn.Open(); using (SqlDataReader reader = cmd.ExecuteReader()) { if (!reader.HasRows) { lblMsg.Text = "There are no products available for that category."; } else { while (reader.Read()) { Control product = new Control(); LiteralControl html = new LiteralControl(); html.Text = "<div class=\"product\">"; html.Text += " <div class=\"details\">"; html.Text += " <h3 class=\"name\">" + reader["Name"].ToString() + "</h3>"; html.Text += " <p class=\"price\">" + reader["Price"].ToString() + "</p>"; html.Text += reader["ButtonCode"].ToString(); html.Text += " </div>"; html.Text += " <div class=\"clear\"></div>"; html.Text += "</div>"; product.Controls.Add(html); divProducts.Controls.Add(product); } } } } } catch { lblMsg.Text = "Could not retrieve products from the database. Please try again later. If the problem persists, please let us know by emailing us"; }}\[/code\]Expected markup for Add to Cart button to be put on the page...\[code\]<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="http://stackoverflow.com/questions/13989635/_s-xclick"> <input type="hidden" name="hosted_button_id" value="http://stackoverflow.com/questions/13989635/7WJXCJ5KGDFLA"> <input type="image" src="https://www.paypalobjects.com/en_GB/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="PayPal
 
Back
Top