OK. Please feel free to post here when there're anything else we can help.
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: "Andrew Robinson" <
[email protected]>
| References: <
[email protected]>
<
[email protected]>
<
[email protected]>
<
[email protected]>
| Subject: Re: Update property from within a control
| Date: Sat, 5 Nov 2005 07:07:12 -0800
| Lines: 351
| 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: <#
[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
| NNTP-Posting-Host: c-67-170-0-134.hsd1.wa.comcast.net 67.170.0.134
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.buildingcontrols:4426
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
|
| Steven,
|
| Thanks. I think this is what I was looking for. Will give it a try.
|
| -Andrew
|
| | > Hi Andrew,
| >
| > Thanks for your response and the furthur description.
| > So I've got that your main concerns is how to initializing(through
| > design-time code) the Control's certain property at design-time (only
| > once
| > after it been draged onto the webform page) , and that property need to
be
| > persisted so that its design-time initialized value also be utilized by
| > runtime , yes?
| >
| > After some furthur research, I'm currently finding a way which can help
| > initialize a propety and persist it in HTML attribute at design-time.
To
| > do
| > this, we need to provide a custom ControlDeisgner for our control, and
in
| > the Designer's overrided "Initialize" method, we intialize that property
| > (the intialize method could be called multiple times, so we can add
code
| > to
| > check the propety and only assigned initial value once....). After
that,
| > in the "GetDesignTimeHTML" method, we manually persist the property
value
| > into the Control's DEsigntime inline HTML (in aspx content). Thus, at
| > runtime we can get the value we intilized at design-time from the
| > persisted
| > attribute. Here is the new sample control's code :
| >
| > ==========================
| > using System;
| > using System.Web.UI;
| > using System.Web.UI.WebControls;
| > using System.ComponentModel;
| > using System.ComponentModel.Design;
| > using System.Web.UI.Design;
| > using System.Drawing.Design;
| > using System.Runtime.Serialization;
| > using WINDOWS = System.Windows.Forms;
| >
| >
| > namespace DTControlLib
| > {
| > /// <summary>
| > /// Summary description for GuidControl.
| > /// </summary>
| > [DefaultProperty("Text"),
| > ToolboxData("<{0}:GuidControl runat=server></{0}:GuidControl>")]
| > [Designer(typeof(GuidControlDesigner), typeof(IDesigner))]
| > public class GuidControl :
| > System.Web.UI.WebControls.WebControl,INamingContainer
| > {
| > private string _guid = Guid.Empty.ToString();
| >
| >
| > [Browsable(false)]
| >
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
| > [PersistenceMode(PersistenceMode.Attribute)]
| > public string DesignTimeGuid
| > {
| > get{return _guid;}
| > set{_guid = value;}
| > }
| >
| > protected override void CreateChildControls()
| > {
| > Controls.Clear();
| >
| >
| > Label lbl = new Label();
| > lbl.ID = "lblGuid";
| > lbl.Text = _guid;
| >
| > Controls.Add(lbl);
| > }
| >
| >
| >
| > }
| >
| > public class GuidControlDesigner : ControlDesigner
| > {
| > public override string GetDesignTimeHtml()
| > {
| > GuidControl gc = this.Component as GuidControl;
| >
| > if(gc==null)
| > {
| > throw new Exception("DesignTime error of GuidControl.");
| > }
| >
| >
| > this.Behavior.SetAttribute("DesignTimeGuid", gc.DesignTimeGuid,false);
| >
| >
| >
| >
| > return "<br><font size='20' color='red'>" + gc.DesignTimeGuid +
| > "</font>";
| > }
| >
| >
| > public override void Initialize(IComponent component)
| > {
| > base.Initialize (component);
| >
| > GuidControl gc = component as GuidControl;
| >
| > if(gc==null)
| > {
| > throw new Exception("DesignTime error of GuidControl.");
| > }
| >
| > if(gc.DesignTimeGuid ==null || gc.DesignTimeGuid == string.Empty ||
| > gc.DesignTimeGuid == Guid.Empty.ToString())
| > {
| > gc.DesignTimeGuid = Guid.NewGuid().ToString();
| > }
| >
| >
| >
| > }
| >
| >
| >
| > }
| > }
| > ===============================
| >
| >
| > 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: "Andrew Robinson" <
[email protected]>
| > | References: <
[email protected]>
| > <
[email protected]>
| > | Subject: Re: Update property from within a control
| > | Date: Fri, 4 Nov 2005 09:15:29 -0800
| > | Lines: 162
| > | 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: <
[email protected]>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > | NNTP-Posting-Host: 216.57.203.121
| > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| > | Xref: TK2MSFTNGXA01.phx.gbl
| > microsoft.public.dotnet.framework.aspnet.buildingcontrols:4417
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > |
| > | Steven,
| > |
| > | I haven't tried this yet, but I think you missed the point of the
| > question
| > | that I was asking or I don't understand how what you are suggesting
will
| > | work and solve my issue. I have built server controls before.
| > |
| > | I am mainly looking for the ability of the control to set a property
at
| > | design time that is then accessable at runtime. This property / value
| > will
| > | be based on code in the control. I am mainly interested in the control
| > | generating a GUID when it is first added to a form at design time.
This
| > | seems like the hard part. I then would read that GUID back at run time
| > (the
| > | eary part.) I don't want to require the user to enter a GUID with each
| > | instance of my control.
| > |
| > | Thanks,
| > |
| > | -Andrew
| > |
| > |
| > |
| > | | > | > Hi Andrew,
| > | >
| > | > Welcome to ASPNET newsgroup.
| > | > Regarding on the adding a property in Custom Webserver control which
| > can
| > | > be
| > | > edited and persisted in control template at design-time and being
| > utilized
| > | > by control code at runtime, here are some of my understanding and
| > | > suggestions;
| > | >
| > | > Actually, this is a buildin and natural feature of the ASP.NET
custom
| > | > webserver control. We can provide a normal property of buildin .net
| > basic
| > | > types and apply attribute on the property so a to determine whether
| > this
| > | > property will be persisted in control's content (aspx page) and how
| > will
| > | > it
| > | > be persisted (as attribute or as inner property). For example,
suppose
| > we
| > | > have the following custom web control:
| > | >
| > | > ===========================
| > | > [DefaultProperty("Text"),
| > | > ToolboxData("<{0}:MyWebControl runat=server></{0}:MyWebControl>")]
| > | > public class MyWebControl : System.Web.UI.WebControls.WebControl
| > | > {
| > | > private string _msg = "default message.";
| > | >
| > | > [Category("Content")]
| > | > [System.Web.UI.PersistenceMode(PersistenceMode.Attribute)]
| > | > public string Message
| > | > {
| > | > get{return _msg;}
| > | > set{_msg = value;}
| > | > }
| > | >
| > | >
| > | > protected override void Render(HtmlTextWriter output)
| > | > {
| > | > output.Write(
| > | > string.Format("<font color='red' ><br/>Message:{0}</font>",Message)
| > | > );
| > | > }
| > | > }
| > | > ====================
| > | >
| > | >
| > | > We add a "Message" property and apply the
| > | > "System.Web.UI.PersistenceMode" attribute which specify that we
persit
| > the
| > | > Property as Attribute, then in VS.NET at design-time after we
change
| > the
| > | > property in property window, the aspx content change to:
| > | >
| > | > ==================
| > | > <cc1:MyWebControl id="MyWebControl1" runat="server"
| > Message="defauldsfdft
| > | > message."></cc1:MyWebControl>
| > | > ====================
| > | >
| > | >
| > | > In addition, for define other complex type property, we may need to
| > define
| > | > more custom components such as TypeConvertor for converting our
custom
| > | > type
| > | > To and From string which can be persisted in page's content (aspx
| > | > template...). Here are some related articles and reference:
| > | >
| > | >
| > | > #Control Parsing, ParseChildrenAttribute, and Control Builders
| > | >
| >
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconcontrolparsingcust
| > | > omattributescontrolbuilders.asp?frame=true
| > | >
| > | > #Enhancing Design-Time Support
| > | >
| >
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconenhancingdesign-ti
| > | > mesupport.asp?frame=true
| > | >
| > | >
| >
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconattributesdesign-t
| > | > imesupport.asp?frame=true
| > | >
| > | >
| > | > #A Custom Dialog Box Control
| > | >
http://www.codeproject.com/aspnet/customdialog.asp
| > | >
| > | > 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: "Andrew Robinson" <>
| > | > | Subject: Update property from within a control
| > | > | Date: Thu, 3 Nov 2005 15:54:25 -0800
| > | > | Lines: 23
| > | > | 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: <
[email protected]>
| > | > | Newsgroups:
| > microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > | > | NNTP-Posting-Host: 216.57.203.121
| > | > | Path:
| > TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
| > | > | Xref: TK2MSFTNGXA01.phx.gbl
| > | > microsoft.public.dotnet.framework.aspnet.buildingcontrols:4414
| > | > | X-Tomcat-NG:
| > microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > | > |
| > | > | I would like to build a server control that updates (at design
time)
| > one
| > | > of
| > | > | its own properties. This property would then be embeded in the
HTML
| > of
| > | > the
| > | > | page and then saved. Later at run time, the control could retrieve
| > this
| > | > | property.
| > | > |
| > | > | <xx:mycontrol id="abc" runat="server" myproperty="zyx" />
| > | > |
| > | > | where myproperty is assigned by the control at design time. This
| > value
| > | > would
| > | > | change at design time as the user sizes the control.
| > | > |
| > | > |
| > | > | make sense? any way of doing this?
| > | > |
| > | > | secondly, is there a way of automatically assigning a GUID at
desing
| > | > time
| > | > so
| > | > | that every control on a site has a unique ID. this would happen
| > | > | automatically when the control is placed on the form.
| > | > |
| > | > |
| > | > | Thanks,
| > | > |
| > | > | Andrew
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|