Ie. 나는를 Page_LoadASP.NET 세션 장바구니 항목로드시 품목 문제가 업데이트되지 않음
Dim subTotal As Integer = 0
For Each item As CartItem In ShoppingCart.Instance.Items
subTotal += 1
Next
strShoppingCart.Append(subTotal).Append(" Items")
shoppingCartItems.Text = strShoppingCart.ToString()
에 내 페이지 다음에 코드 조각을 그리고 객체와 하위 Update_Click (ByVal의 보낸 사람, ByVal의 전자로 보호
을 다음과 같이 나는 다음 내 장바구니에 항목을 추가 할 수 있습니다 있는 EventArgs) 정수 = productListTable.Rows.Count
For Each row As GridViewRow In productListTable.Rows
If row.RowType = DataControlRowType.DataRow Then
' We'll use a try catch block in case something other than a number is typed in. If so, we'll just ignore it.
Try
' Get the productId from the GridView's datakeys
Dim productId = Convert.ToInt32(productListTable.DataKeys(row.RowIndex).Value)
' Find the quantity TextBox and retrieve the value
Dim quantity = Integer.Parse(CType(row.Cells(1).FindControl("txtQuantity"), TextBox).Text)
'Dim price = Decimal.Parse(CType(row.Cells(1).FindControl("TradePriceField"), Label).Text)
Dim price = Decimal.Parse("16.00")
Dim productName = CType(row.Cells(1).FindControl("ProductNameField"), Label).Text
Dim packSize = Integer.Parse(CType(row.Cells(1).FindControl("PackSizeField"), Label).Text)
Dim stockIndicator = Integer.Parse(CType(row.Cells(1).FindControl("PackSizeField"), Label).Text)
ShoppingCart.Instance.AddItem(productId, quantity, price, productName, packSize, stockIndicator)
Catch ex As FormatException
End Try
End If
Next
End Sub
로서 어둡게 rowscount
페이지로드를,617 다음 문제는개 항목 세션 1 개 항목이 나는 올바른 세션 수에서 읽을 수 있습니다 어떻게
에 카운터가가는 페이지를 새로 고침 실제로있을 때 0
나는 페이지가 여전히 0 항목라는 제품을 추가한다 카운트 ?
안녕하세요 rsbarro 질문 답변 모든 클릭에 대한 응답은 매우 무거운 리소스로 보이거나 틀렸습니까? 또한 Update_Click 메서드를 사용하여 ShoppingCartItems를 업데이트 한 다음 어떻게 할 수 있습니까? 예를 들어 ShoppingCart.Instance.AddItem (productId, quantity, price, productName, packSize, stockIndicator) – StevieB
Page_reRender의 세션 수를 표시하는 코드를 배치하는 것은 Update_Click 메서드 트릭을 완료했습니다 – StevieB
@StevieB : 리디렉션 접근 방식이 리소스가 무겁다고 생각하지 않습니다. 재 게시 대화 상자가 혼란스럽고 (페이지 새로 고침이나 뒤로 단추, 앞으로 단추 누르기와 같은 여러 상황에서 표시 될 수 있기 때문에) 사용자 경험을 향상시키는 것이 필요하다고 생각합니다. ASP.NET의 표준 접근법은 Page_Load에 데이터를 바인딩하는 것입니다.이 데이터는 포스트 백일 경우 (예 : if (! Page.IsPostBack) DataBindMyControls();)입니다. 버튼 클릭과 같은 모든 다시 게시 이벤트는 업데이트해야하는 항목을 업데이트 할 수 있으며, Response.Redirect를 사용하여 페이지를 다시로드 할 수 있습니다. – rsbarro