Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 24th, 2008, 12:28 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default Passing Templates in a Composite Control

Hello Everyone,
   This may be a bit difficult to explain but I am going to try. I wrote a composite control that consists of various controls but the control of importance here is a custom repeater control that I wrote. Now, if I were to drop this Repeater control onto a web form I can easily supply it with a Template (Header, Item, Footer) just as I would with the standard Repeater control.

I ran headlong into a wall, however, when I placed this Repeater control inside of my Composite control since there was no apparent way for me to supply a template on the WebForm that would then be passed to my Repeater Control.

After rigorous searches on Google the only thing that I could turn up that was worthwhile was how to implement Templates in custom controls that inherited from a control like the Repeater, GridView, etc which I have already done inside of my Repeater control. So what I ended up doing was something like this:

    ToolboxData("<{0}:CustomContainerControl runat=\"server\"></{0}:CustomContainerControl>")]
public class CustomContainer : CompositeControl, INamingContainer
   private ITemplate containerItemTemplate;
   private Control containerItemControl;
   public virtual ITemplate ItemTemplate
      get { return containerItemTemplate; }
      set { containerItemTemplate = value; }
   protected override void CreateChildControls()
     CustomRepeater rpr = new CustomRepeater();
     if (ItemTemplate != null){ ItemTemplate.InstantiateIn(containerItemControl); }
     rpr.ID = "rpr";
     rpr.ItemTemplate = ItemTemplate;
I obviously have properties that deal with Header and Footer Items that I have omitted here. By using the above code I am able to achieve something like this:

<cc1:CustomContainerControl ID="container" runat="server">
<tr><td bgcolor="#ffffff"><%#Eval("Foo")%></td></tr>
Everything works as I want it to: everything defined in the above template is passed to my Repeater control and is displayed correctly. The problem is I can't help but feel that this is the "short cut" way of doing things and that a more efficient , albeit complex, way exists.

Any opinions and/or critiques are welcome!


================================================== =========
Read this if you want to know how to get a correct reply for your question:
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chp.5 composite control properties studen77 BOOK: Professional ASP.NET 2.0 Server Control and Component Development ISBN: 978-0-471-79350-2 1 October 6th, 2006 03:35 PM
Composite Control Part 2 origjones General .NET 2 September 18th, 2006 03:28 AM
Building composite Control with Image + DDL mehdi_tn ASP.NET 2.0 Professional 1 April 12th, 2006 10:48 PM
PLEASE HELP - Composite Control brettk_1 ASP.NET 1.0 and 1.1 Professional 0 August 3rd, 2005 06:22 AM
Composite Control bmains .NET Framework 2.0 0 July 25th, 2005 12:57 PM

All times are GMT -4. The time now is 02:58 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.