WebControl with Collection Property in Design Time
- From: "Mirek Endys" <MirekE@xxxxxxxxxxxxxxxx>
- Date: Wed, 2 Nov 2005 12:54:02 +0100
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 );
}
}
}
.
- Follow-Ups:
- RE: WebControl with Collection Property in Design Time
- From: Steven Cheng[MSFT]
- RE: WebControl with Collection Property in Design Time
- Prev by Date: Clickable labels
- Next by Date: RE: referring to a third-party contol in window.onload
- Previous by thread: Clickable labels
- Next by thread: RE: WebControl with Collection Property in Design Time
- Index(es):
Relevant Pages
|
Loading