WebControl with Collection Property in Design Time



Hallo,

I need to create WebControl, that stores List of Hyperlinks.
I have problem in design-time.
When I add an hyperlinks, they are rendered in contents, hyperlinks are
vsible on page.
In case I switch into source and then back into design, the control says:

Error Creating Control - WebNavigation1
'cc1:WebNavigation' could not be set on property 'Hyperlinks'.

Im wrong, but I dont know where. Could you help me? Source is bellow.

using System;

using System.IO;

using System.Collections.Generic;

using System.Collections;

using System.Drawing.Design;

using System.ComponentModel;

using System.Text;

using System.Web;

using System.Web.UI;

using System.Web.UI.Design;

using System.Web.UI.WebControls;

namespace WebNavigation

{

public class WebNavigationDesigner : System.Web.UI.Design.ControlDesigner

{

public override string GetDesignTimeHtml ()

{

WebNavigation wn = (WebNavigation) Component;

StringWriter sw = new StringWriter ();

HtmlTextWriter tw = new HtmlTextWriter ( sw );


foreach ( HyperLink hl in wn.Hyperlinks )

{

hl.RenderControl ( tw );

}

return sw.ToString ();


}

}

//[DefaultProperty ( "Hyperlinks" )]

[ToolboxData ( "<{0}:WebNavigation runat=server></{0}:WebNavigation>" )]

[Designer ( "WebNavigation.WebNavigationDesigner, WebNavigation" )]

[ParseChildren(true, "Hyperlinks")]

public class WebNavigation : WebControl

{


[DefaultValue(100)]

[Browsable(true)]

[Bindable ( true )]

public override Unit Width

{

get

{

return base.Width;

}

set

{

base.Width = value;

}

}

[Bindable ( true )]

[Category ( "Appearance" )]

[DefaultValue ( "" )]

[Localizable ( true )]

public string Caption

{

get

{

String s = (String) ViewState["Caption"];

return ( ( s == null ) ? String.Empty : s );

}

set

{

ViewState["Caption"] = value;

}

}


protected override void RenderContents ( HtmlTextWriter writer )

{

foreach ( HyperLink hl in _Hyperlinks )

this.Controls.Add ( hl );

base.RenderContents ( writer);

}

private List<HyperLink> _Hyperlinks;

//[Editor(typeof(List<HyperLink>), typeof(UITypeEditor))]

[DesignerSerializationVisibility ( DesignerSerializationVisibility.Content)]

[PersistenceMode ( PersistenceMode.InnerDefaultProperty)]

public List<HyperLink> Hyperlinks

{

get

{

if ( _Hyperlinks == null )

_Hyperlinks = new List<HyperLink> ();

return _Hyperlinks;

}

set

{

foreach(HyperLink hl in value)

this.Controls.Add(hl);

_Hyperlinks = value;

}

}


protected override void AddedControl ( Control control, int index )

{

base.AddedControl ( control, index );

}

}

}




.



Relevant Pages

  • Re: WebControl with Collection Property in Design Time
    ... > when I just drag this control onto a form. ... Why do you put the following Attribute on the HyperLinks property? ... > get any problem on working on it at runtime or design-time, ... > public class WebNavigationDesigner: ControlDesigner ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • RE: WebControl with Collection Property in Design Time
    ... you're developing a custom web server control (in ... For Collection property in .NET Custom Control, ... public ListHyperlinks ... | WebNavigation wn = Component; ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: WebControl with Collection Property in Design Time
    ... Microsoft Online Support ... |> when I just drag this control onto a form. ... Why do you put the following Attribute on the HyperLinks property? ... |> | Subject: Re: WebControl with Collection Property in Design Time ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: WebControl with Collection Property in Design Time
    ... Since HyperLink is buildin control types, the IDE can correctly use the ... Edit the "HyperLinks" collection through property Grid(a Collection ... | Subject: Re: WebControl with Collection Property in Design Time ... | public class WebNavigationDesigner: ControlDesigner ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: WebControl with Collection Property in Design Time
    ... This control will contain a count of HyperLink controls. ... - I will add hyperlinks by design-time property toolbox. ... parsed from/to the page in design time. ... > | Subject: RE: WebControl with Collection Property in Design Time ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)

Loading