也就是說,我有一段代碼,我的頁面,如下所示,這是在Page_Load中ASP.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的) 昏暗rowscount爲整數= 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
的問題是如下
頁面加載 個項目計數爲0
我添加產品頁面仍然說0項目時,居然有在會議 1項我刷新計數器進入的頁面,以一個
我怎樣才能從正確的會話數讀?
嘿rsbarro問題response.redirecting每一次點擊似乎非常資源重或我錯了嗎?另外我怎樣才能update_click更新ShoppingCartItems我以爲我正在更新Update_Click方法即ShoppingCart.Instance.AddItem(productId,數量,價格,productName,packSize,stockIndicator) – StevieB
啊把我的代碼顯示會話計數在Page_PreRender似乎已經完成了這個技巧 – StevieB
@StevieB:我不認爲重定向方法是資源沉重的。我認爲它是改善用戶體驗的必要條件,因爲轉貼對話框很混亂(並且可以在多種情況下顯示,例如頁面刷新或後退按鈕,然後轉發按鈕單擊)。 ASP.NET中的標準方法是綁定Page_Load中的數據,並考慮它是否爲回發(即if(!Page.IsPostBack)DataBindMyControls();)'。任何回發事件(比如按鈕點擊)都可以更新他們需要更新的任何內容,然後您可以直接使用Response.Redirect重新加載頁面。 – rsbarro