I'm building a product catalog which displays between 50/100 products per page. Since I want to have different browse sections on my site I've put each product into a UserControl. Well, not the products themselves ofcourse, but some labels, divs and images. I then set its properties in run-time when processing the database results. So the advantage is that I only have to change the product control at 1 place for the whole site. I'm putting the controls in a page using LoadControl in a loop.
However the pages are not loading quite as fast as other pages which process the same db query and output the same html using a StringBuilder. And since I want my site to perform well if/when it receives some decent traffic I'm worried about this. I haven't done any benchmarkings yet but I clearly see the difference.
Well enough of my problems! My questions to you is 'Are there any alternatives which are faster then using LoadControl with a customcontrol but are easily maintained (or atleast in 1 location)?'
I was thinking of:
- Creating a customcontrol (although I've never done it and don't know 100% if this will speed things up)
- Continue with the StringBuilder method and put the CreateProduct in my base class
- Ditching the whole idea of maintaining the product in 1 location
I hope you guys have had similar situations choices so I'd really like to hear from you!
[edit]Code[/edit] I don't have the excact usercontrol code here but I will edit this post when I get home..but here is the simplified idea:
1) Getting my database result (using Subsonic 2.2 as my DAL)
DAL.ProductCollection coll = new DAL.ProductCollection();
if(coll.count > 0)
{
foreach(DAL.Product item in coll)
{
Control p = LoadControl("FeaturedProduct.ascx");
placeholder.Controls.Add(p);
//Set properties
p.title = item.Title;
p.img = GetImage(item.Guid);
....etc
}
}
My usercontrol itselves just consists of 3 Literal controls and 1 Image control.
But I will post complete code when I arrive home! Thanks