User Control Template Not Working

Posted on 2009-04-15
Last Modified: 2012-05-06
I am trying to create a user control that allows the use of a template to show the data.

But I get no data displayed when I use

<ItemTemplate>Test:<%# Container.ItemId %></ItemTemplate>

If I do not create the template.... I do see the "template not defined" error as expected.

I have attached the files that I am using to demonstrate my problem.
Question by:spencerturbine
    LVL 8

    Accepted Solution


    Two theories:

    1) The Default2.aspx needs to manually call WebUserCall1.DataBind() method.  For some reason, I think if you do not declartively set either DataSourceID or DataSource properties the DataBind method is not called by the ASP.NET Page LifeCycle and you'll need to manually call the DataBind method.  You can safely call WebUserCall1.DataBind() from the Default2 PageLoad event handler.

    2) The WebUserControl.ascx OnInit() event is fired before the ItemID property is set.  Try using the OnLoad or OnDataBind event instead.

    Let me know if that works for you.


    Author Closing Comment

    Databind worked like a charm!


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now