Re: WebControl with Collection Property in Design Time
- From: "Mirek Endys" <MirekE@xxxxxxxxxxxxxxxx>
- Date: Fri, 11 Nov 2005 09:33:52 +0100
No, it is not working. I will try to explain it again.
What I need
------------------------------------------------------
I need to create my own Web Server Control.
This control will contain a count of HyperLink controls.
I need this control has design-time support:
- I will add hyperlinks by design-time property toolbox.
- This properties (including hyperlinks) will be stored and will be
editable (add/remove)
whole design time by property toolbox.
- This control and its style will be displayed in design-time on the web
page
My control was able to edit hyperlinks, by property toolbox (collection
editor)
in designtime, but I can only add the HyperLinks but the second time
I open the property collection editor, the hyperlinks are gone.
Thats because they arent stored.
I think, that the control must working by this way:
- in case HyperLinks are edited (added, removed) they must be
parsed from/to the page (or into the control) in design time.
I was able (but not now) to parse them to page in design time, but not FROM
page
into property toolbox (collection editor)
Well, and now, what I did
--------------------------------------
public class WebNavigationDesigner : ControlDesigner
{
public override string GetDesignTimeHtml()
{
WebNavigation wNavigation = (WebNavigation)Component;
StringWriter sWriter = new StringWriter();
HtmlTextWriter htWriter = new HtmlTextWriter(sWriter);
foreach(HyperLink hyperlink in wNavigation.Hyperlinks)
hyperlink.RenderControl(htWriter);
return sWriter.ToString();
}
}
[DefaultProperty("Hyperlinks")]
[ToolboxData("<{0}:WebNavigation runat=server></{0}:WebNavigation>")]
[Designer("WebNavigationDesigner", "WebNavigation")]
[ParseChildren(true, "Hyperlinks")]
public class WebNavigation : WebControl
{
private List<HyperLink> _Hyperlinks = null;
protected override void RenderContents(HtmlTextWriter output)
{
foreach(HyperLink hLink in _Hyperlinks)
hLink.RenderControl(output);
}
[Bindable(true)]
[Category("Data")]
[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;
}
}
}
==============================================================
Thats simplified problem, please help me to get this simple
control to life.
Thanks
Mirek
--------------------------------------------------------------
"Steven Cheng[MSFT]" <stcheng@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:l28wCl64FHA.1172@xxxxxxxxxxxxxxxxxxxxxxxx
> Hi Mirek,
>
> How are you doing on this issue. Does the suggestions in my last reply
> helps you resolve the problem? if there're anything else we can help,
> please feel free to post here. Thanks,
>
> Steven Cheng
> Microsoft Online Support
>
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>
>
>
> --------------------
> | X-Tomcat-ID: 120657561
> | References: <#1WrfQ63FHA.2872@xxxxxxxxxxxxxxxxxxxx>
> | MIME-Version: 1.0
> | Content-Type: text/plain
> | Content-Transfer-Encoding: 7bit
> | From: stcheng@xxxxxxxxxxxxxxxxxxxx (Steven Cheng[MSFT])
> | Organization: Microsoft
> | Date: Thu, 03 Nov 2005 06:57:47 GMT
> | Subject: RE: WebControl with Collection Property in Design Time
> | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
> | Message-ID: <lYD#xPE4FHA.2904@xxxxxxxxxxxxxxxxxxxxx>
> | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
> | Lines: 133
> | Path: TK2MSFTNGXA01.phx.gbl
> | Xref: TK2MSFTNGXA01.phx.gbl
> microsoft.public.dotnet.framework.aspnet.webcontrols:11644
> | NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122
> |
> | Hi Mirek,
> |
> | Welcome to ASPNET newsgroup.
> | From you description, you're developing a custom web server control (in
> | asp.net 2.0) which contains a collection property and you found that the
> | control always throw out "could not be set on property" error when
> | swtiching between HTML view and design-view in VS.NET IDE(2005) , YES?
> |
> | Based on my experience, this problem is caused by our Collection
> property's
> | declaration. For Collection property in .NET Custom Control, we can only
> | provide getter accessor for it, in other world it should be defined as
> | readonly. Like:
> | ===========
> | public List<HyperLink> Hyperlinks
> | {
> |
> | get
> | {
> |
> | if ( _Hyperlinks == null )
> |
> | _Hyperlinks = new List<HyperLink> ();
> |
> | return _Hyperlinks;
> |
> | }
> |
> | //no setter needed
> |
> | }
> | ==============
> |
> | For Collection property, we just need to add/remove items from it, do
> not
> | need to modify the Collection reference itself. Also, we can find that
> | those collection property in ASP.NET buildin controls are just defined
> as
> | readonly(Getter only...). So you can remove the setter accessor in your
> | control's Hyperlinks property.
> |
> | Hope helps. Thanks,
> |
> | Steven Cheng
> | Microsoft Online Support
> |
> | Get Secure! www.microsoft.com/security
> | (This posting is provided "AS IS", with no warranties, and confers no
> | rights.)
> |
> |
> |
> |
> |
> |
> |
> | --------------------
> | | From: "Mirek Endys" <MirekE@xxxxxxxxxxxxxxxx>
> | | Subject: WebControl with Collection Property in Design Time
> | | Date: Wed, 2 Nov 2005 12:54:02 +0100
> | | Lines: 209
> | | X-Priority: 3
> | | X-MSMail-Priority: Normal
> | | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
> | | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
> | | X-RFC2646: Format=Flowed; Original
> | | Message-ID: <#1WrfQ63FHA.2872@xxxxxxxxxxxxxxxxxxxx>
> | | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
> | | NNTP-Posting-Host: gw.coty.cz 195.47.52.129
> | | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
> | | Xref: TK2MSFTNGXA01.phx.gbl
> | microsoft.public.dotnet.framework.aspnet.webcontrols:11628
> | | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
> | |
> | | 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
- References:
- WebControl with Collection Property in Design Time
- From: Mirek Endys
- RE: WebControl with Collection Property in Design Time
- From: Steven Cheng[MSFT]
- WebControl with Collection Property in Design Time
- Prev by Date: RE: Finding a way to bind ASP.NET controls(two way) to a typed-dat
- Next by Date: Re: WebControl with Collection Property in Design Time
- Previous by thread: RE: WebControl with Collection Property in Design Time
- Next by thread: Re: WebControl with Collection Property in Design Time
- Index(es):
Relevant Pages
|