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

Discussion in 'ASP .Net' started by LaptopHeaven, Oct 5, 2006.

  1. LaptopHeaven

    LaptopHeaven Guest

    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.
     
    LaptopHeaven, Oct 5, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. owais
    Replies:
    3
    Views:
    1,050
    Francois Bonin [C# MVP]
    Jun 23, 2005
  2. J
    Replies:
    3
    Views:
    7,131
  3. saurabh
    Replies:
    2
    Views:
    476
    Oystein Haare
    May 5, 2004
  4. Replies:
    0
    Views:
    276
  5. Thomas Wagner

    Problem with usercontrol/itemplate

    Thomas Wagner, Aug 16, 2007, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    146
    Thomas Wagner
    Aug 16, 2007
Loading...

Share This Page