ASP.NET Custom control with collection property

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • -=Chris=-

    ASP.NET Custom control with collection property

    Hello all,

    I've designed a custom bread crumb control for several of my asp.net
    projects. The default property of this control is a custom
    HyperLinkCollec tion I've created, which contains, you guessed it, HyperLink
    objects. All of it works great if I create/assign the links at runtime in
    code. I'd like to be able to assign links at design time, which is possible
    using the properties window, but currently, they do not carry over to the
    runtime. I'm trying to figure out how to make this happen. Sample code for
    the small breadcrumb class is listed below. I would greatly appreciate any
    input.

    using System;

    using System.Collecti ons;

    using System.Web.UI;

    using System.Web.UI.W ebControls;

    using System.Componen tModel;

    namespace Com.L3Software. Web.Controls {

    /// <summary>

    /// Summary description for Breadcrumb.

    /// </summary>

    [DefaultProperty ("Crumbs"),

    Designer("Com.L 3Software.Web.C ontrols.Breadcr umbDesigner"),

    ToolboxData("<{ 0}:Breadcrumb runat=server></{0}:Breadcrumb> "),

    Description("A reusable breadcrumb component")]

    public class Breadcrumb : System.Web.UI.W ebControls.WebC ontrol,
    INamingContaine r {

    private HyperLinkCollec tion mCrumbs;

    [Bindable(false) ,

    Category("Appea rance"),

    Description("An ordered list of links to be displayed")]

    public HyperLinkCollec tion Crumbs {

    get {

    return this.mCrumbs;

    }

    }

    public Breadcrumb() {

    this.mCrumbs = new HyperLinkCollec tion();

    }

    /// <summary>

    /// Render this control to the output parameter specified.

    /// </summary>

    /// <param name="output"> The HTML writer to write out to </param>

    protected override void Render(HtmlText Writer output) {

    output.Write("Y ou are here: ");

    for (int i=0; i<this.mCrumbs. Count; i++) {

    HyperLink l = (HyperLink)this .mCrumbs[i];

    l.RenderControl (output);

    if (i < this.mCrumbs.Co unt-1)

    output.Write(" >> ");

    }

    }

    }

    }


    --
    Insert corny line here


  • Natty Gur

    #2
    Re: ASP.NET Custom control with collection property

    Hi,

    you need to use some design time attribute. you can read about them on
    MSDN:

    /html/cpconattributes design-timesupport.asp

    or look at sample code :


    HTH

    Natty Gur[MVP]

    blog : http://weblogs.asp.net/ngur
    Mobile: +972-(0)58-888377


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!

    Comment

    • -=Chris=-

      #3
      Re: ASP.NET Custom control with collection property

      Thanks. It took a little time to figure it out, since the code changes
      didn't show up right away in the designers I'd already created, but got it
      figured out. Thanks again!

      --
      Insert corny line here
      "Natty Gur" <natty@dao2com. com> wrote in message
      news:eA0g6vHQEH A.2452@TK2MSFTN GP11.phx.gbl...[color=blue]
      > Hi,
      >
      > you need to use some design time attribute. you can read about them on
      > MSDN:
      > http://msdn.microsoft.com/library/de.../en-us/cpguide
      > /html/cpconattributes design-timesupport.asp
      >
      > or look at sample code :
      > http://www.asp-files.com/msg/391.html
      >
      > HTH
      >
      > Natty Gur[MVP]
      >
      > blog : http://weblogs.asp.net/ngur
      > Mobile: +972-(0)58-888377
      >
      >
      > *** Sent via Developersdex http://www.developersdex.com ***
      > Don't just participate in USENET...get rewarded for it![/color]


      Comment

      Working...