I'm developing a webshop. The product category page consists of boxes with products. Each product box is a UserWebControl (CategoryProductBox). CategoryProductBox exposes a property that accepts a product object.
Depending on some properties of the product object the CategoryProductBox is rendered deferently. Ei displaying a "sale"-picture in the corner.
The CategoryProductBox is all inside a Panel. In the load event of CategoryProductBox I look at the product properties and determine if the "sale"-picture is going to be displayed. If so the BackImageUrl of the Panel is set.
This works flawlessly when I render one CategoryProductBox. But if I render two or more all get rendered the same way as the last one (all get the "sale"-picture if the last one has it). I guess it's because all Panels in the controlls are named the same
in some way.
On the other hand... Labels containing price and product name gets different (correct) values in the different rendered CategoryProductBoxes.
Bit of a long shot here without seeing any code...
Are you persisting the user control property using Session? If so, you may be overwriting the value if the control doesn't declare a unique key for the session. If so, try using ViewState instead.
If you're not doing this, can you post the code where you initialize all of user controls with products?
Links
Member
22 Points
15 Posts
All instances of a UserWebControll is affected by code in one
Mar 08, 2011 05:10 PM|LINK
I'm developing a webshop. The product category page consists of boxes with products. Each product box is a UserWebControl (CategoryProductBox). CategoryProductBox exposes a property that accepts a product object.
Depending on some properties of the product object the CategoryProductBox is rendered deferently. Ei displaying a "sale"-picture in the corner.
The CategoryProductBox is all inside a Panel. In the load event of CategoryProductBox I look at the product properties and determine if the "sale"-picture is going to be displayed. If so the BackImageUrl of the Panel is set.
This works flawlessly when I render one CategoryProductBox. But if I render two or more all get rendered the same way as the last one (all get the "sale"-picture if the last one has it). I guess it's because all Panels in the controlls are named the same in some way.
On the other hand... Labels containing price and product name gets different (correct) values in the different rendered CategoryProductBoxes.
What am I doing wrong?
stu.b
Member
110 Points
15 Posts
Re: All instances of a UserWebControll is affected by code in one
Mar 08, 2011 09:04 PM|LINK
Hi,
Bit of a long shot here without seeing any code...
Are you persisting the user control property using Session? If so, you may be overwriting the value if the control doesn't declare a unique key for the session. If so, try using ViewState instead.
If you're not doing this, can you post the code where you initialize all of user controls with products?
http://openheartnerdery.co.uk
MadhuriM
Member
703 Points
151 Posts
Re: All instances of a UserWebControll is affected by code in one
Mar 08, 2011 09:13 PM|LINK
How are you implementing this in the load event handler? Are you inside a for loop?
It would be nice if you posted some code-
Links
Member
22 Points
15 Posts
Re: All instances of a UserWebControll is affected by code in one
Mar 09, 2011 06:30 AM|LINK
public partial class CategoryProductBox : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { if (Product.PublishStop > DateTime.Today.AddDays(-7)) { PanelMain.BackImageUrl = "../images/utgaende.png"; } else if (Product.PriceSpecial != -1) { PanelMain.BackImageUrl = "../images/rea.png"; } else { LabelPrice.Text = Product.Price.ToString(); } } public Product Product { get; set; } }Links
Member
22 Points
15 Posts
Re: All instances of a UserWebControll is affected by code in one
Mar 09, 2011 06:31 AM|LINK
<div style="float:left; height:200px; width:140px; margin:20px;"> <asp:Panel ID="PanelMain" runat="server" style="float:left; width:138px; height:200px; border: solid 1px #d6d6d6;"> <!--<div id="MainDiv" style="float:left; width:138px; height:200px; border: solid 1px #d6d6d6;">--> <asp:Label ID="LabelPrice" runat="server" Text="- kr"></asp:Label> </asp:Panel> <img src="images/productlistshadow.png" /> </div>Links
Member
22 Points
15 Posts
Re: All instances of a UserWebControll is affected by code in one
Mar 09, 2011 06:31 AM|LINK
Links
Member
22 Points
15 Posts
Re: All instances of a UserWebControll is affected by code in one
Mar 09, 2011 06:45 AM|LINK
Well.. Euhm.. Found the error.. it was the the first if that got true when it shouldn't...
Thanks for your help anyway.