Programmaticly load a custom UserControl with in a custom class which implements an ITemplate

L

LaptopHeaven

I am having some trouble. How would one load a custom UserControl fro
within a class which impements the ITemplate interface.

Currently I have the following:

public class SmallProductViewTemplate : ITemplate
{
public void InstantiateIn(Control container)
{
HyperLink productImage = new HyperLink();
productImage.CssClass = "ProductImage";
productImage.DataBinding += new
EventHandler(ProductImage_DataBinding);
container.Controls.Add(productImage);

//other asp.net controls are loaded here...
}

...

private void ProductImage_DataBinding(object sender, EventArgs e)
{
HyperLink image = (HyperLink)sender;
DataListItem container = (DataListItem)image.NamingContainer;
image.ImageUrl = String.Format("{0}{1}{2}",
SiteConstants.ImageBaseUrl, SiteConstants.SmallImagePath,
DataBinder.GetPropertyValue(container.DataItem,
"ImageSmallFileName").ToString());
image.NavigateUrl = String.Format("{0}?productID={1}",
PageConstants.Product, DataBinder.GetPropertyValue(container.DataItem,
"ProductID").ToString());
image.Text = DataBinder.GetPropertyValue(container.DataItem,
"DisplayName").ToString();
}
}

Instead of loading a bunch of asp.net controls, I would like to load a
single user control, which encapsulates the design, to use inside the
template.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top