Problem with usercontrol/itemplate

Discussion in 'ASP .Net Web Controls' started by Thomas Wagner, Aug 16, 2007.

  1. Hi group,

    I try to develop a gallery control, that uses templates for displaying.
    Everything should (as I can say) be correct, but "InstantiateIn" does not
    get the right data from my container-class.

    The source looks like this, could someone please help me, I have no idea
    what I did wrong!
    (Note: When I change "Container.Url" to "Container.XXX", the compiler
    recognizes, that XXX is not a member of ImageTemplateContainer.)

    Thank you
    Thomas

    /* Container: */

    public class ImageTemplateContainer : Control, INamingContainer
    {
    private String m_strUrl;
    public String Url
    {
    get
    {
    return m_strUrl;
    }
    }

    public ImageTemplateContainer(String NavUrl)
    {
    this.m_strUrl = NavUrl;
    }
    }

    /* Control: */

    [ToolboxData("<{0}:Gallery runat=server></{0}:Gallery>")]
    [ParseChildren(true)]
    [PersistChildren(false)]
    public class Gallery : WebControl, INamingContainer
    {
    private ITemplate m_ImageTemplate = null;

    [Browsable(false)]
    [PersistenceMode(PersistenceMode.InnerProperty)]
    [TemplateContainer(typeof(ImageTemplateContainer))]
    public virtual ITemplate ImageTemplate
    {
    get { return m_ImageTemplate; }
    set { m_ImageTemplate = value; }
    }

    private ImageTemplateContainer m_itcContainer;
    public ImageTemplateContainer Container
    {
    get
    {
    return m_itcContainer;
    }
    }

    protected override void CreateChildControls()
    {
    if (m_ImageTemplate != null)
    {
    Controls.Clear();

    m_itcContainer = new ImageTemplateContainer("imagetest.jpg");
    m_ImageTemplate.InstantiateIn(m_itcContainer);

    Controls.Add(m_itcContainer);
    }
    else
    {
    this.Controls.Add(new LiteralControl("Nixda"));
    }

    //base.CreateChildControls();
    }
    }
    /* aspx */

    <cc1:Gallery ID="Gallery1" runat="server" EnableViewState="true" >
    <ImageTemplate><%# Container.Url %></imageTemplate>
    </cc1:Gallery>
     
    Thomas Wagner, Aug 16, 2007
    #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. huobazi
    Replies:
    1
    Views:
    699
    David Waz...
    Jul 3, 2003
  2. LaptopHeaven
    Replies:
    0
    Views:
    411
    LaptopHeaven
    Oct 5, 2006
  3. DC
    Replies:
    2
    Views:
    347
  4. Rbrt

    iTemplate Formview Problem

    Rbrt, Feb 7, 2008, in forum: ASP .Net
    Replies:
    3
    Views:
    745
    Coskun SUNALI [MVP]
    Feb 7, 2008
  5. Mark van Bree

    Postback problem with usercontrol in usercontrol

    Mark van Bree, May 30, 2006, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    165
Loading...

Share This Page