Monday, March 26, 2012

Shopping Basket at Top of Page?

I really hope someone can help me as I am tearing my hair out with thisone. I am just starting with ASP.net and have the following pageworking:
A main form containing a list of products in a repeater object with an add button on each line.
A user control in the shape of a basket contents list (another repeater) at the very top of the page.
I have some code that fires on the ItemCommand event of the main form'srepeater object that adds an item into the shopping basket.
This code works as I can see the items add successfully into the database.
BUT
The shopping basket list at the top of the page is always one item BEHIND what has been added in the main page.
This is because the main repeat object's ItemCommand event does notfire until AFTER the code to list the items in the shopping basket hasalready run. Thus, when the database is asked what is in the basketit does not include the latest item that the user has just asked to be added.
Having a shopping basket listed before the main product list (in a usercontrol) is such a common requirement that there must be a solution.
What is it?
Thanks in advance for your help.
Monty

Assuming your usercontrols has a procedure to bind data to the bask repeater then make that procedure public. Now assuming your usercontrol is called basket1 and the classname is basket then when someone adds an item you can call that procedure from the pages code:-
CType(Me.FindControl("basket1"), basket).mybinddataprocedure

0 comments:

Post a Comment