The problem is this:
You are binding the basket data BEFORE you add an item.
[u]Explanation</u>
You have the following method declaration:
Sub Page_Prerender(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
The key to the problem is the "Handles MyBase.Load". This tells this method to run when the page loads.
When ASP.NET processes events, they happen after the page is loaded. You are binding the basket data, and THEN the button click event handler (AddItemToBasket) is called. The basket data has already been generated before the item is added resulting in a delay in the data that you are seeing on the page.
Typically, the way this should work is something like the following.
When the page loads
- Prefill controls only on the FIRST page load (based on IsPostback)
You can do this because the controls will maintain their one data between postbacks. You don't need to prefill them every time.
Any event that affects the data that shows up in the controls:
- Modify the data based on the event that is being called (i.e. Add item to shopping basket)
- Update controls that reflect this output.
Here's how it would basically work for you:
Code:
Sub Page_Load(...)
If Not IsPostback Then
BindBasket()
End If
End Sub
Sub AddItemToBasket(...)
'TODO: Add the item to the basket here
BindBasket()
End Sub
Sub BindBasket()
'TODO: Load the basket data
'TODO: Bind it to the basketlist
End Sub
Peter
------------------------------------------------------
Work smarter, not harder.