저는 전자 상거래 웹 사이트에서 일하고 있으며 현재 카트 섹션에서 일하고 있습니다. 이제 장바구니에 추가 된 모든 제품이 정적 목록에 저장됩니다. 목록의 모든 제품에 대해 생성 된 html 코드가 있습니다.
protected void btnCart_Click(object sender, EventArgs e)
{
//Show howmany items are in the cart list
lblCartCount.Text = "There are currently " + (CartList.Count()).ToString() + " items in your cart";
//Clear current cart-html code
CartProducts.InnerHtml = String.Empty;
//Foreach product in the cart list
for (int i = 0; i < CartList.Count; i++)
{
//Get necessary info about the current looped product
var TupleProductInfo = B.GetProductInfo(CartList[i]);
int ProductID = TupleProductInfo.Item1;
String ProductSize = TupleProductInfo.Item2;
double ProductPrice = TupleProductInfo.Item3;
//Foreach product cleate cart-html
CartProducts.InnerHtml +=
"<div class='CartProduct'>" +
"<div>" +
"<h4>" + B.GetProductName(ProductID) + "</h4>" +
"<button id='btnDeleteProduct' runat='server' onserverclick='btnDeleteProduct_click' title='remove product'>" +
"<i class='fas fa-times fa-lg'></i>" +
"</button >" +
"</div>" +
"<div>" +
"<p>Size: " + ProductSize + "</p>" +
"<p>Price: €" + Math.Round(ProductPrice, 2) + "</p>" +
"<p>Amount: " + CartListAmount[i].ToString() + "</p>" +
"</div>" +
"</div>";
}
//Show the cart
popupCart.Style.Add("display", "flex");
}
<div runat="server" id="CartProducts" class="margin2"></div>
카트에서 제품을 삭제하는 버튼이 각각 있습니다.
<button id='btnDeleteProduct' runat='server' onserverclick='btnDeleteProduct_click' title='remove product'>
장바구니에서 제품을 삭제하기 위해 버튼을 클릭하면 C # 함수를 호출하고 싶습니다.
protected void btnDeleteProduct_click(object sender, EventArgs e){ ... }
함수가 호출되지 않습니다.
내 문제를 살펴봐 주셔서 감사합니다! 해결책을 알고 있거나 대안이 있으면 알려주십시오. Stack Overflow를 100 % 올바르게 사용하지 않았다면 실례합니다. 어떤 팁이라도 환영합니다!
미리 감사드립니다!
얼마 동안 시도한 후에도 여전히 함수를 호출 할 수 없습니다 (위의 제안을 시도했습니다). 그래서 다음과 같이 해결했습니다. 장바구니에있는 모든 제품으로 세션을 만들고 별도의 페이지로 리디렉션되었습니다. 이 페이지에서 데이터 목록을 만들고 세션의 모든 항목을 선택하는 SelectCommand를 작성했습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다