CreateChildControls() always returns default property values

Discussion in 'ASP .Net Web Controls' started by Christophe Peillet, Jan 14, 2006.

  1. I am trying to develop a composite control that renders in a specific layout,
    depending on the value of the custom LabelPosition property. The 'layout' of
    the rendered control will change depending on whether the value of
    LabelPosition is set to Left, Right, Top, or Bottom, as can be seen in the
    CreateChildControls() method.

    This particular class (included below) actually acts as a base class for
    many other controls (such as a textbox, checkbox, datepicker, etc.), so not
    all of the logic is implemented here. Because I don't know what objects will
    need to be added by the child controls (textbox, etc.), I have inserted a
    PlaceHolder control in the appropriate section of the table, and child
    controls insert their own objects here. (This allows me to keep the code for
    rendering the table in the parent class, making code maintenance much easier
    for me if changes are ever needed.)

    The problem I'm having is that no matter which value I assign to the
    LabelPosition property, it always returns the default value inside the
    CreateChildControls() method. I explicitly set it to Top, and this appears
    in the Html code behind, but it is always the default (Left) when I set and
    reach a breakpoint in CreateChildControls().

    I'm sure my problem is that I have not properly understood the composite
    control page model, and am setting default values in the wrong place (look at
    the SetDefaultValues() method reference in the constructor), or am creating
    the table in the wrong place (based on the 'switch' in
    CreateChildControls()). Or, the problem could be something with ViewState,
    that I am not properly storing/refreshing the value of the LabelPosition
    property.

    If anyone can help me understand why this value is not being restored, and
    always reads as default, I would enormously appreciate it, since I've spend
    many hours on this to no avail, including a lot of time on Google.

    The base class is included below. If you need the Designer class (which
    contains nothing exotic) or a child class (that implements this base class),
    let me know any I'll post it.

    PS: Because of maximum message length, I have trimmed some unneccessary
    properties from the code.

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.ComponentModel;
    using System.ComponentModel.Design;
    using System.Diagnostics;
    using System.Drawing.Design;
    using Telerik.WebControls;

    namespace CompanyName.EEE.Web.UI.FormControls
    {
    /// <summary>
    /// The BaseClass used in all of CompanyName's form custom form controls
    which require a descriptive label.
    /// </summary>
    // [Designer(typeof(SupportFormLabelledControlDesigner))]
    [DefaultProperty("LabelText")]
    [ToolboxData("<{0}:SupportFormLabelledControl
    runat=\"server\"></{0}:SupportFormLabelledControl>")]
    public abstract class SupportFormLabelledControl : SupportFormControl,
    INamingContainer, ICallback, IRequired
    {

    #region Protected Fields

    // Any third-party or external controls that you wish to add to the
    this
    // control, such as buttons, labels, etc., should be declared here.
    By
    // declaring them 'protected' they will be visible in any control that
    // inherits from SupportFormLabelledControl

    /// <summary>The Table used to hold child controls on the
    form</summary>
    protected Table m_tbl;
    /// <summary>The CallbackLabel rendered with the control</summary>
    protected CallbackLabel m_lbl;
    /// <summary>The Warning Icon rendered with the control when <see
    cref="P:Required"/> is set to <c>true</c></summary>
    protected IconPopupControl m_icn;
    /// <summary>The content PlaceHolder used to insert any child
    controls that need to be added (Textboxes, Checkboxes, etc).</summary>
    protected PlaceHolder m_plc;

    #endregion

    #region Constructor

    // Default values for properties should ONLY be defined in the the
    // class constructor. If you set properties elsewhere, such as in the
    // OnLoad event, you will make the control insensitive to external,
    // tag-level settings.

    /// <summary>
    /// Initializes a new instance of the <see
    cref="SupportFormLabelledControl"/> class.
    /// </summary>
    public SupportFormLabelledControl()
    {
    // Set control default values
    this.SetDefaultValues();
    }

    #endregion

    #region Abstract Members

    /// <summary>
    /// If the control's Required property is set to True, this method
    can be
    /// used to validate whether the Required conditions are met or not.
    /// </summary>
    /// <returns>
    /// <c>true</c> if the Required conditions are met, <c>false</c> if
    they are not.
    /// </returns>
    public abstract bool ValidateControl();

    #endregion

    #region Protected Methods

    /// <summary>
    /// Raises the <see cref="E:System.Web.UI.Control.Init"></see> event.
    /// </summary>
    /// <param name="e">An <see cref="T:System.EventArgs"></see> object
    that contains the event data.</param>
    protected override void OnInit(EventArgs e)
    {
    base.OnInit(e);
    }

    /// <summary>
    /// Raises the <see cref="E:System.Web.UI.Control.Load"></see> event.
    /// </summary>
    /// <param name="e">The <see cref="T:System.EventArgs"></see> object
    that contains the event data.</param>
    protected override void OnLoad(EventArgs e)
    {
    // This method captures the controls Load event (declared and
    bound in the
    // class constructor). RunTime rendering takes place in this
    method (as
    // opposed to DesignMode rendering, which takes place elsewhere).

    // Call base Load method
    base.OnLoad(e);

    EnsureChildControls();
    }

    /// <summary>
    /// Called by the ASP.NET page framework to notify server controls
    that use
    /// composition-based implementation to create any child controls
    they contain
    /// in preparation for posting back or rendering.
    /// </summary>
    protected override void CreateChildControls()
    {
    // Clear the control collection
    Controls.Clear();

    // Any dependant controls used in this custom control must
    // be added to the control 'hierarchy'. If they are not added
    // to the control collection, they will not be visible to other
    // controls on the page.

    // Instantiate any dependant controls
    m_tbl = new Table();
    m_lbl = new CallbackLabel();
    m_icn = new IconPopupControl();
    m_plc = new PlaceHolder();

    // Create table object and format it through relevant method
    m_tbl =
    SharedFunctions.CreateLabelledControlTable(this.LabelPosition);

    // Add table to the control collection
    Controls.Add(m_tbl);

    // Add controls to the table control collection
    switch (this.LabelPosition)
    {
    case Position.Left:
    m_tbl.Rows[0].Cells[0].Controls.Add(m_lbl);
    m_tbl.Rows[0].Cells[1].Controls.Add(m_plc);
    m_tbl.Rows[0].Cells[1].Controls.Add(m_icn);
    // Set relevant design properties
    m_tbl.Rows[0].Cells[0].Width = new
    Unit(this.LabelWidth.ToString());
    break;
    case Position.Top:
    m_tbl.Rows[0].Cells[0].Controls.Add(m_lbl);
    m_tbl.Rows[1].Cells[0].Controls.Add(m_plc);
    m_tbl.Rows[1].Cells[0].Controls.Add(m_icn);
    // Set relevant design properties
    m_tbl.Rows[0].Cells[0].Width = new
    Unit(this.LabelWidth.ToString());
    break;
    case Position.Right:
    m_tbl.Rows[0].Cells[0].Controls.Add(m_plc);
    m_tbl.Rows[0].Cells[0].Controls.Add(m_icn);
    m_tbl.Rows[0].Cells[1].Controls.Add(m_lbl);
    // Set relevant design properties
    m_tbl.Rows[0].Cells[1].Width = new
    Unit(this.LabelWidth.ToString());
    break;
    case Position.Bottom:
    m_tbl.Rows[0].Cells[0].Controls.Add(m_plc);
    m_tbl.Rows[0].Cells[0].Controls.Add(m_icn);
    m_tbl.Rows[1].Cells[0].Controls.Add(m_lbl);
    // Set relevant design properties
    m_tbl.Rows[1].Cells[0].Width = new
    Unit(this.LabelWidth.ToString());
    break;
    default:
    Debug.Assert(false);
    break;
    }

    // Call base method
    base.CreateChildControls();
    }

    protected override void OnPreRender(EventArgs e)
    {
    // Call base method
    base.OnPreRender(e);

    // Associate dependent control properties with this control's
    properties
    m_lbl.CssClass = this.LabelCssClass;
    m_lbl.Text = this.LabelText;
    m_lbl.Visible = this.LabelVisible;
    m_lbl.RadControlsDir = this.ScriptsPath;
    m_lbl.CallbackEnabled = this.CallbackEnabled;
    m_lbl.DisableAtCallback = this.DisableAtCallback;
    m_lbl.Enabled = this.Enabled;
    m_icn.WarningImageUrl = this.WarningImageUrl;
    m_icn.ImageAlign = this.ImageAlign;
    m_icn.EmptyImageUrl = this.EmptyImageUrl;
    m_icn.MessageStyle = this.MessageStyle;
    m_icn.PopupText = this.PopupText;
    m_icn.PopupTextResourceKey = this.PopupTextResourceKey;
    m_icn.PopupTitle = this.PopupTitle;
    m_icn.PopupTitleResourceKey = this.PopupTitleResourceKey;
    m_icn.LinkUrl = this.LinkUrl;
    m_icn.Enabled = this.Enabled;
    m_icn.CssClass = this.WarningIconCssStyle;

    // Enable or disable warning icon as appropriate
    m_icn.Visible = this.Required ? true : false;
    }

    #endregion

    #region Private/Internal Methods

    /// <summary>
    /// Sets the control's default values.
    /// </summary>
    private void SetDefaultValues()
    {
    // Set default properties
    this.LabelPosition = Position.Left;
    this.LabelText = string.Empty;
    this.LabelCssClass = SharedConstants.SupportForm_LabelStyle;
    this.LabelVisible = true;
    this.LabelWidth = new
    Unit(SharedConstants.SupportForm_DefaultLabelWidth);
    this.Required = false;
    this.CallbackEnabled =
    SharedConstants.SupportForm_CallbackEnabledByDefault;
    this.DisableAtCallback =
    SharedConstants.SupportForm_DisableAtCallback;
    this.ScriptsPath = SharedConstants.SupportForm_DefaultScriptsPath;
    this.AutoPostback = false;
    this.ImageAlign = ImageAlign.AbsMiddle;
    this.LinkUrl = string.Empty;
    this.MessageStyle = MessageStyle.NoMessage;
    this.PopupText = string.Empty;
    this.PopupTextResourceKey = string.Empty;
    this.PopupTitle = string.Empty;
    this.PopupTitleResourceKey = string.Empty;
    this.WarningIconVisible = false;
    this.WarningIconCssStyle =
    SharedConstants.SupportForm_WarningIconStyle;
    this.WarningImageUrl =
    SharedConstants.SupportForm_IconPopupControlDefaultWarningImageUrl;
    this.EmptyImageUrl =
    SharedConstants.SupportForm_IconPopupControlDefaultEmptyImageUrl;
    }

    /// <summary>
    /// Sets the design mode values.
    /// </summary>
    internal virtual void SetDesignModeValues()
    {
    // Ensure child controls are created
    EnsureChildControls();

    // Associate dependent control properties with this control's
    properties
    m_lbl.CssClass = this.LabelCssClass;
    m_lbl.Text = this.LabelText == string.Empty ? "[LabelText]" :
    this.LabelText;
    m_lbl.Visible = this.LabelVisible;
    m_lbl.RadControlsDir = this.ScriptsPath;
    m_lbl.CallbackEnabled = this.CallbackEnabled;
    m_lbl.DisableAtCallback = this.DisableAtCallback;
    m_lbl.Enabled = this.Enabled;
    m_icn.WarningImageUrl = this.WarningImageUrl;
    m_icn.ImageAlign = this.ImageAlign;
    m_icn.EmptyImageUrl = this.EmptyImageUrl;
    m_icn.MessageStyle = this.MessageStyle;
    m_icn.PopupText = this.PopupText;
    m_icn.PopupTextResourceKey = this.PopupTextResourceKey;
    m_icn.PopupTitle = this.PopupTitle;
    m_icn.PopupTitleResourceKey = this.PopupTitleResourceKey;
    m_icn.LinkUrl = this.LinkUrl;
    m_icn.WarningIconVisible = this.WarningIconVisible;
    m_icn.Enabled = this.Enabled;
    m_icn.CssClass = this.WarningIconCssStyle;
    if (this.Required)
    {
    m_icn.Visible = true;
    }
    else
    {
    m_icn.Visible = false;
    }
    // For DesignMode, always display the warning icon
    m_icn.WarningIconVisible = true;
    }

    #endregion

    #region Public Properties

    /// <summary>
    /// Gets or sets a value indicating whether this control uses AJAX
    callback functionality or not.
    /// </summary>
    /// <value><c>true</c> if callback enabled; otherwise,
    <c>false</c>.</value>
    [Bindable(true)]
    [Category("Callback")]
    [Description("Whether this control uses callback functionality or
    not.")]
    public bool CallbackEnabled
    {
    get
    {
    bool b = (bool)ViewState["IsCallback"];
    return b;
    }
    set
    {
    ViewState["IsCallback"] = value;
    }
    }

    /// <summary>
    /// Gets or sets a value indicating whether this control is disabled
    during callback.
    /// </summary>
    /// <value><c>true</c> if disabled during callback; otherwise,
    <c>false</c>.</value>
    [Bindable(true)]
    [Category("Callback")]
    [Description("Whether this control is disabled while a background
    callback is in effect.")]
    public bool DisableAtCallback
    {
    get
    {
    bool b = (bool)ViewState["DisableAtCallback"];
    return b;
    }
    set
    {
    ViewState["DisableAtCallback"] = value;
    }
    }

    /// <summary>
    /// The location of the RadControls folder, containing the required
    JavaScript support files.
    /// </summary>
    /// <value>The scripts path.</value>
    [Bindable(true)]
    [Category("Callback")]
    [Description("The location of the RadControls folder, containing the
    required JavaScript support files.")]
    public string ScriptsPath
    {
    get
    {
    String s = (String)ViewState["ScriptsPath"];
    return ((s == null) ? String.Empty : s);
    }
    set
    {
    Debug.Assert(value != null, "Warning: ScriptsPath property
    is null!");
    if (value != null)
    {
    ViewState["ScriptsPath"] = value;
    }
    else
    {
    throw new NullReferenceException("ScriptsPath can not be
    assigned a null value.");
    }
    }
    }

    /// <summary>
    /// Gets or sets the position of the descriptive label relative to
    the rest of the control.
    /// </summary>
    /// <value>The label position.</value>
    [Bindable(true)]
    [Category("Label")]
    [DefaultValue(Position.Left)]
    [Localizable(false)]
    [Description("The position of the descriptive label relative to the
    rest of the control.")]
    public Position LabelPosition
    {
    get
    {
    Position p = (Position)ViewState["LabelPosition"];
    return p;
    }
    set
    {
    ViewState["LabelPosition"] = value;
    }
    }

    /// <summary>
    /// Gets or sets the text displayed in the descriptive label.
    /// </summary>
    /// <value>The label text.</value>
    [Bindable(true)]
    [Category("Label")]
    [DefaultValue("")]
    [Localizable(true)]
    [Description("The text to display in the descriptive label.")]
    public string LabelText
    {
    get
    {
    EnsureChildControls();
    String s = (String)ViewState["LabelText"];
    return ((s == null) ? String.Empty : s);
    }
    set
    {
    Debug.Assert(value != null, "Warning: LabelText property is
    null!");
    if (value != null)
    {
    ViewState["LabelText"] = value;
    }
    else
    {
    throw new NullReferenceException("LabelText can not be
    assigned a null value.");
    }
    }
    }

    /// <summary>
    /// Gets or sets the label text resource key.
    /// </summary>
    /// <value>The label text resource key.</value>
    [Bindable(true)]
    [Category("Label")]
    [DefaultValue("")]
    [Localizable(false)]
    public string LabelTextResourceKey
    {
    get
    {
    String s = (String)ViewState["LabelTextResourceKey"];
    return ((s == null) ? String.Empty : s);
    }
    set
    {
    Debug.Assert(value != null, "Warning: LabelTextResourceKey
    property is null!");
    if (value != null)
    {
    ViewState["LabelTextResourceKey"] = value;
    }
    else
    {
    throw new NullReferenceException("LabelTextResourceKey
    can not be assigned a null value.");
    }
    }
    }

    /// <summary>
    /// Gets or sets the label CSS class.
    /// </summary>
    /// <value>The label CSS class.</value>
    [Bindable(true)]
    [Category("Label")]
    [DefaultValue("")]
    [Localizable(false)]
    public string LabelCssClass
    {
    get
    {
    string s = (string)ViewState["LabelTextCssClass"];
    return (s == null) ? String.Empty : s;
    }
    set
    {
    Debug.Assert(value != null, "Warning: LabelCssClass property
    is null!");
    if (value != null)
    {
    ViewState["LabelTextCssClass"] = value;
    }
    else
    {
    throw new NullReferenceException("LabelTextCssClass can
    not be assigned a null value.");
    }
    }
    }

    /// <summary>
    /// Gets or sets a value indicating whether label is visible.
    /// </summary>
    /// <value><c>true</c> if label is visible; otherwise,
    <c>false</c>.</value>
    [Bindable(true)]
    [Category("Label")]
    [DefaultValue(true)]
    [Localizable(false)]
    public bool LabelVisible
    {
    get
    {
    bool b = (bool)ViewState["LabelVisible"];
    return (b);
    }
    set
    {
    ViewState["LabelVisible"] = value;
    }
    }

    /// <summary>
    /// Gets or sets the width of the label.
    /// </summary>
    /// <value>The width of the label.</value>
    [Bindable(true)]
    [Category("Label")]
    [Localizable(false)]
    [Description("The width of the descriptive label.")]
    public Unit LabelWidth
    {
    get
    {
    Unit u = (Unit)ViewState["LabelWidth"];
    return (u);
    }
    set
    {
    Debug.Assert(value != null, "Warning: LabelWidth property is
    null!");
    ViewState["LabelWidth"] = value;
    }
    }

    /// <summary>
    /// Gets or sets a value indicating whether the <see
    cref="SupportFormLabelledControl"/> is required.
    /// If required is set to true, than a validating <see
    cref="IconPopupControl"/> will be added to this control.
    /// </summary>
    /// <value><c>true</c> if required; otherwise, <c>false</c>.</value>
    [Bindable(true)]
    [Category("Required")]
    [DefaultValue(false)]
    [Localizable(false)]
    [Description("Determines whether the Required icon validator is
    present on this control or not.")]
    public bool Required
    {
    get
    {
    bool b = (bool)ViewState["Required"];
    return (b);
    }
    set
    {
    ViewState["Required"] = value;
    }
    }

    /// <summary>
    /// Gets or sets a value indicating whether to automatically post
    back when the control is clicked.
    /// </summary>
    /// <value><c>true</c> if controls posts back when clicked;
    otherwise, <c>false</c>.</value>
    [Bindable(true)]
    [Category("Behavior")]
    [DefaultValue(typeof(bool), "False")]
    [Description("Automatically posts back to the server when the
    control is clicked.")]
    [Localizable(false)]
    public bool AutoPostback
    {
    get
    {
    bool b = (bool)ViewState["AutoPostBack"];
    return b;
    }
    set
    {
    ViewState["AutoPostBack"] = value;
    }
    }

    /// <summary>
    /// Gets or sets the URL of the image to display when
    WarningIconVisible is set to true.
    /// </summary>
    /// <value>The warning image URL.</value>
    [Bindable(false)]
    [Category("Required")]
    [Localizable(false)]
    [Editor("System.Web.UI.Design.ImageUrlEditor, System.Design,
    Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
    typeof(UITypeEditor))]
    [Description("The image to display when WarningIconVisible is set to
    true.")]
    public string WarningImageUrl
    {
    get
    {
    string s = (string)ViewState["WarningImageUrl"];
    return (s == null) ? String.Empty : s;
    }
    set
    {
    Debug.Assert(value != null, "Warning: WarningImageUrl
    property is null!");
    if (value != null)
    {
    ViewState["WarningImageUrl"] = value;
    }
    else
    {
    throw new NullReferenceException("WarningImageUrl can
    not be assigned a null value.");
    }
    }
    }

    /// <summary>
    /// Gets or sets the URL of the page to open when the required
    icon's MessageStyle is set to UrlLink.
    /// </summary>
    /// <value>The link URL.</value>
    [Bindable(false)]
    [Category("Required")]
    [Localizable(false)]
    [Editor("System.Web.UI.Design.UrlEditor, System.Design,
    Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
    typeof(UITypeEditor))]
    [Description("The URL of the page to open when the Required icon's
    MessageStyle is set to UrlLink.")]
    public string LinkUrl
    {
    get
    {
    string s = (string)ViewState["LinkUrl"];
    return (s == null) ? String.Empty : s;
    }
    set
    {
    Debug.Assert(value != null, "Warning: LinkUrl property is
    null!");
    if (value != null)
    {
    ViewState["LinkUrl"] = value;
    }
    else
    {
    throw new NullReferenceException("LinkUrl can not be
    assigned a null value.");
    }
    }
    }

    /// <summary>
    /// Gets or sets the type of message to display when the user clicks
    or moves their mouse over the required icon.
    /// </summary>
    /// <value>The message style.</value>
    [Bindable(false)]
    [Category("Required")]
    [Localizable(false)]
    [DefaultValue(MessageStyle.NoMessage)]
    [Description("The type of message to display when the user clicks or
    moves their mouse over the Required icon.")]
    public MessageStyle MessageStyle
    {
    get
    {
    MessageStyle m = (MessageStyle)ViewState["MessageStyle"];
    return m;
    }
    set
    {
    ViewState["MessageStyle"] = value;
    }
    }

    /// <summary>
    /// Gets or sets the body text to use in the popup window when
    MessageStyle is set to PopupMessage.
    /// </summary>
    /// <value>The popup text.</value>
    [Bindable(false)]
    [Category("Required")]
    [Localizable(true)]
    [Description("The body text to use in the popup window when
    MessageStyle is set to PopupMessage.")]
    public string PopupText
    {
    get
    {
    string s = (string)ViewState["PopupText"];
    return (s == null) ? String.Empty : s;
    }
    set
    {
    Debug.Assert(value != null, "Warning: PopupText property is
    null!");
    if (value != null)
    {
    ViewState["PopupText"] = value;
    }
    else
    {
    throw new NullReferenceException("PopupText can not be
    assigned a null value.");
    }
    }
    }

    /// <summary>
    /// Gets or sets the resource key of the body text to use in the
    popup window when MessageStyle is set to PopupMessage.
    /// </summary>
    /// <value>The popup text.</value>
    [Bindable(false)]
    [Category("Required")]
    [Localizable(true)]
    public string PopupTextResourceKey
    {
    get
    {
    string s = (string)ViewState["PopupTextResourceKey"];
    return (s == null) ? String.Empty : s;
    }
    set
    {
    Debug.Assert(value != null, "Warning: PopupTextResourceKey
    property is null!");
    if (value != null)
    {
    ViewState["PopupTextResourceKey"] = value;
    }
    else
    {
    throw new NullReferenceException("PopupTextResourceKey
    can not be assigned a null value.");
    }
    }
    }

    /// <summary>
    /// Gets or sets the title to use in the popup window when
    MessageStyle is set to PopupMessage.
    /// </summary>
    /// <value>The popup title.</value>
    [Bindable(false)]
    [Category("Required")]
    [Localizable(true)]
    [Description("The title to use in the popup window when MessageStyle
    is set to PopupMessage.")]
    public string PopupTitle
    {
    get
    {
    string s = (string)ViewState["PopupTitle"];
    return (s == null) ? String.Empty : s;
    }
    set
    {
    Debug.Assert(value != null, "Warning: PopupTitle property is
    null!");
    if (value != null)
    {
    ViewState["PopupTitle"] = value;
    }
    else
    {
    throw new NullReferenceException("PopupTitle can not be
    assigned a null value.");
    }
    }
    }

    #endregion
    }
    }
     
    Christophe Peillet, Jan 14, 2006
    #1
    1. Advertising

  2. Christophe Peillet

    Axel Dahmen Guest

    Too big, I'm afraid. Who's supposed to read that??

    Axel Dahmen


    -----------
    "Christophe Peillet" <> schrieb im
    Newsbeitrag news:...
    > I am trying to develop a composite control that renders in a specific

    layout,
    > depending on the value of the custom LabelPosition property. The 'layout'

    of
    > the rendered control will change depending on whether the value of
    > LabelPosition is set to Left, Right, Top, or Bottom, as can be seen in the
    > CreateChildControls() method.
    >
    > This particular class (included below) actually acts as a base class for
    > many other controls (such as a textbox, checkbox, datepicker, etc.), so

    not
    > all of the logic is implemented here. Because I don't know what objects

    will
    > need to be added by the child controls (textbox, etc.), I have inserted a
    > PlaceHolder control in the appropriate section of the table, and child
    > controls insert their own objects here. (This allows me to keep the code

    for
    > rendering the table in the parent class, making code maintenance much

    easier
    > for me if changes are ever needed.)
    >
    > The problem I'm having is that no matter which value I assign to the
    > LabelPosition property, it always returns the default value inside the
    > CreateChildControls() method. I explicitly set it to Top, and this

    appears
    > in the Html code behind, but it is always the default (Left) when I set

    and
    > reach a breakpoint in CreateChildControls().
    >
    > I'm sure my problem is that I have not properly understood the composite
    > control page model, and am setting default values in the wrong place (look

    at
    > the SetDefaultValues() method reference in the constructor), or am

    creating
    > the table in the wrong place (based on the 'switch' in
    > CreateChildControls()). Or, the problem could be something with

    ViewState,
    > that I am not properly storing/refreshing the value of the LabelPosition
    > property.
    >
    > If anyone can help me understand why this value is not being restored, and
    > always reads as default, I would enormously appreciate it, since I've

    spend
    > many hours on this to no avail, including a lot of time on Google.
    >
    > The base class is included below. If you need the Designer class (which
    > contains nothing exotic) or a child class (that implements this base

    class),
    > let me know any I'll post it.
    >
    > PS: Because of maximum message length, I have trimmed some unneccessary
    > properties from the code.
    >
    > using System;
    > using System.Collections.Generic;
    > using System.Text;
    > using System.Web;
    > using System.Web.UI;
    > using System.Web.UI.WebControls;
    > using System.ComponentModel;
    > using System.ComponentModel.Design;
    > using System.Diagnostics;
    > using System.Drawing.Design;
    > using Telerik.WebControls;
    >
    > namespace CompanyName.EEE.Web.UI.FormControls
    > {
    > /// <summary>
    > /// The BaseClass used in all of CompanyName's form custom form

    controls
    > which require a descriptive label.
    > /// </summary>
    > // [Designer(typeof(SupportFormLabelledControlDesigner))]
    > [DefaultProperty("LabelText")]
    > [ToolboxData("<{0}:SupportFormLabelledControl
    > runat=\"server\"></{0}:SupportFormLabelledControl>")]
    > public abstract class SupportFormLabelledControl : SupportFormControl,
    > INamingContainer, ICallback, IRequired
    > {
    >
    > #region Protected Fields
    >
    > // Any third-party or external controls that you wish to add to

    the
    > this
    > // control, such as buttons, labels, etc., should be declared

    here.
    > By
    > // declaring them 'protected' they will be visible in any control

    that
    > // inherits from SupportFormLabelledControl
    >
    > /// <summary>The Table used to hold child controls on the
    > form</summary>
    > protected Table m_tbl;
    > /// <summary>The CallbackLabel rendered with the control</summary>
    > protected CallbackLabel m_lbl;
    > /// <summary>The Warning Icon rendered with the control when <see
    > cref="P:Required"/> is set to <c>true</c></summary>
    > protected IconPopupControl m_icn;
    > /// <summary>The content PlaceHolder used to insert any child
    > controls that need to be added (Textboxes, Checkboxes, etc).</summary>
    > protected PlaceHolder m_plc;
    >
    > #endregion
    >
    > #region Constructor
    >
    > // Default values for properties should ONLY be defined in the the
    > // class constructor. If you set properties elsewhere, such as in

    the
    > // OnLoad event, you will make the control insensitive to

    external,
    > // tag-level settings.
    >
    > /// <summary>
    > /// Initializes a new instance of the <see
    > cref="SupportFormLabelledControl"/> class.
    > /// </summary>
    > public SupportFormLabelledControl()
    > {
    > // Set control default values
    > this.SetDefaultValues();
    > }
    >
    > #endregion
    >
    > #region Abstract Members
    >
    > /// <summary>
    > /// If the control's Required property is set to True, this method
    > can be
    > /// used to validate whether the Required conditions are met or

    not.
    > /// </summary>
    > /// <returns>
    > /// <c>true</c> if the Required conditions are met, <c>false</c>

    if
    > they are not.
    > /// </returns>
    > public abstract bool ValidateControl();
    >
    > #endregion
    >
    > #region Protected Methods
    >
    > /// <summary>
    > /// Raises the <see cref="E:System.Web.UI.Control.Init"></see>

    event.
    > /// </summary>
    > /// <param name="e">An <see cref="T:System.EventArgs"></see>

    object
    > that contains the event data.</param>
    > protected override void OnInit(EventArgs e)
    > {
    > base.OnInit(e);
    > }
    >
    > /// <summary>
    > /// Raises the <see cref="E:System.Web.UI.Control.Load"></see>

    event.
    > /// </summary>
    > /// <param name="e">The <see cref="T:System.EventArgs"></see>

    object
    > that contains the event data.</param>
    > protected override void OnLoad(EventArgs e)
    > {
    > // This method captures the controls Load event (declared and
    > bound in the
    > // class constructor). RunTime rendering takes place in this
    > method (as
    > // opposed to DesignMode rendering, which takes place

    elsewhere).
    >
    > // Call base Load method
    > base.OnLoad(e);
    >
    > EnsureChildControls();
    > }
    >
    > /// <summary>
    > /// Called by the ASP.NET page framework to notify server controls
    > that use
    > /// composition-based implementation to create any child controls
    > they contain
    > /// in preparation for posting back or rendering.
    > /// </summary>
    > protected override void CreateChildControls()
    > {
    > // Clear the control collection
    > Controls.Clear();
    >
    > // Any dependant controls used in this custom control must
    > // be added to the control 'hierarchy'. If they are not added
    > // to the control collection, they will not be visible to

    other
    > // controls on the page.
    >
    > // Instantiate any dependant controls
    > m_tbl = new Table();
    > m_lbl = new CallbackLabel();
    > m_icn = new IconPopupControl();
    > m_plc = new PlaceHolder();
    >
    > // Create table object and format it through relevant method
    > m_tbl =
    > SharedFunctions.CreateLabelledControlTable(this.LabelPosition);
    >
    > // Add table to the control collection
    > Controls.Add(m_tbl);
    >
    > // Add controls to the table control collection
    > switch (this.LabelPosition)
    > {
    > case Position.Left:
    > m_tbl.Rows[0].Cells[0].Controls.Add(m_lbl);
    > m_tbl.Rows[0].Cells[1].Controls.Add(m_plc);
    > m_tbl.Rows[0].Cells[1].Controls.Add(m_icn);
    > // Set relevant design properties
    > m_tbl.Rows[0].Cells[0].Width = new
    > Unit(this.LabelWidth.ToString());
    > break;
    > case Position.Top:
    > m_tbl.Rows[0].Cells[0].Controls.Add(m_lbl);
    > m_tbl.Rows[1].Cells[0].Controls.Add(m_plc);
    > m_tbl.Rows[1].Cells[0].Controls.Add(m_icn);
    > // Set relevant design properties
    > m_tbl.Rows[0].Cells[0].Width = new
    > Unit(this.LabelWidth.ToString());
    > break;
    > case Position.Right:
    > m_tbl.Rows[0].Cells[0].Controls.Add(m_plc);
    > m_tbl.Rows[0].Cells[0].Controls.Add(m_icn);
    > m_tbl.Rows[0].Cells[1].Controls.Add(m_lbl);
    > // Set relevant design properties
    > m_tbl.Rows[0].Cells[1].Width = new
    > Unit(this.LabelWidth.ToString());
    > break;
    > case Position.Bottom:
    > m_tbl.Rows[0].Cells[0].Controls.Add(m_plc);
    > m_tbl.Rows[0].Cells[0].Controls.Add(m_icn);
    > m_tbl.Rows[1].Cells[0].Controls.Add(m_lbl);
    > // Set relevant design properties
    > m_tbl.Rows[1].Cells[0].Width = new
    > Unit(this.LabelWidth.ToString());
    > break;
    > default:
    > Debug.Assert(false);
    > break;
    > }
    >
    > // Call base method
    > base.CreateChildControls();
    > }
    >
    > protected override void OnPreRender(EventArgs e)
    > {
    > // Call base method
    > base.OnPreRender(e);
    >
    > // Associate dependent control properties with this control's
    > properties
    > m_lbl.CssClass = this.LabelCssClass;
    > m_lbl.Text = this.LabelText;
    > m_lbl.Visible = this.LabelVisible;
    > m_lbl.RadControlsDir = this.ScriptsPath;
    > m_lbl.CallbackEnabled = this.CallbackEnabled;
    > m_lbl.DisableAtCallback = this.DisableAtCallback;
    > m_lbl.Enabled = this.Enabled;
    > m_icn.WarningImageUrl = this.WarningImageUrl;
    > m_icn.ImageAlign = this.ImageAlign;
    > m_icn.EmptyImageUrl = this.EmptyImageUrl;
    > m_icn.MessageStyle = this.MessageStyle;
    > m_icn.PopupText = this.PopupText;
    > m_icn.PopupTextResourceKey = this.PopupTextResourceKey;
    > m_icn.PopupTitle = this.PopupTitle;
    > m_icn.PopupTitleResourceKey = this.PopupTitleResourceKey;
    > m_icn.LinkUrl = this.LinkUrl;
    > m_icn.Enabled = this.Enabled;
    > m_icn.CssClass = this.WarningIconCssStyle;
    >
    > // Enable or disable warning icon as appropriate
    > m_icn.Visible = this.Required ? true : false;
    > }
    >
    > #endregion
    >
    > #region Private/Internal Methods
    >
    > /// <summary>
    > /// Sets the control's default values.
    > /// </summary>
    > private void SetDefaultValues()
    > {
    > // Set default properties
    > this.LabelPosition = Position.Left;
    > this.LabelText = string.Empty;
    > this.LabelCssClass = SharedConstants.SupportForm_LabelStyle;
    > this.LabelVisible = true;
    > this.LabelWidth = new
    > Unit(SharedConstants.SupportForm_DefaultLabelWidth);
    > this.Required = false;
    > this.CallbackEnabled =
    > SharedConstants.SupportForm_CallbackEnabledByDefault;
    > this.DisableAtCallback =
    > SharedConstants.SupportForm_DisableAtCallback;
    > this.ScriptsPath =

    SharedConstants.SupportForm_DefaultScriptsPath;
    > this.AutoPostback = false;
    > this.ImageAlign = ImageAlign.AbsMiddle;
    > this.LinkUrl = string.Empty;
    > this.MessageStyle = MessageStyle.NoMessage;
    > this.PopupText = string.Empty;
    > this.PopupTextResourceKey = string.Empty;
    > this.PopupTitle = string.Empty;
    > this.PopupTitleResourceKey = string.Empty;
    > this.WarningIconVisible = false;
    > this.WarningIconCssStyle =
    > SharedConstants.SupportForm_WarningIconStyle;
    > this.WarningImageUrl =
    > SharedConstants.SupportForm_IconPopupControlDefaultWarningImageUrl;
    > this.EmptyImageUrl =
    > SharedConstants.SupportForm_IconPopupControlDefaultEmptyImageUrl;
    > }
    >
    > /// <summary>
    > /// Sets the design mode values.
    > /// </summary>
    > internal virtual void SetDesignModeValues()
    > {
    > // Ensure child controls are created
    > EnsureChildControls();
    >
    > // Associate dependent control properties with this control's
    > properties
    > m_lbl.CssClass = this.LabelCssClass;
    > m_lbl.Text = this.LabelText == string.Empty ? "[LabelText]" :
    > this.LabelText;
    > m_lbl.Visible = this.LabelVisible;
    > m_lbl.RadControlsDir = this.ScriptsPath;
    > m_lbl.CallbackEnabled = this.CallbackEnabled;
    > m_lbl.DisableAtCallback = this.DisableAtCallback;
    > m_lbl.Enabled = this.Enabled;
    > m_icn.WarningImageUrl = this.WarningImageUrl;
    > m_icn.ImageAlign = this.ImageAlign;
    > m_icn.EmptyImageUrl = this.EmptyImageUrl;
    > m_icn.MessageStyle = this.MessageStyle;
    > m_icn.PopupText = this.PopupText;
    > m_icn.PopupTextResourceKey = this.PopupTextResourceKey;
    > m_icn.PopupTitle = this.PopupTitle;
    > m_icn.PopupTitleResourceKey = this.PopupTitleResourceKey;
    > m_icn.LinkUrl = this.LinkUrl;
    > m_icn.WarningIconVisible = this.WarningIconVisible;
    > m_icn.Enabled = this.Enabled;
    > m_icn.CssClass = this.WarningIconCssStyle;
    > if (this.Required)
    > {
    > m_icn.Visible = true;
    > }
    > else
    > {
    > m_icn.Visible = false;
    > }
    > // For DesignMode, always display the warning icon
    > m_icn.WarningIconVisible = true;
    > }
    >
    > #endregion
    >
    > #region Public Properties
    >
    > /// <summary>
    > /// Gets or sets a value indicating whether this control uses AJAX
    > callback functionality or not.
    > /// </summary>
    > /// <value><c>true</c> if callback enabled; otherwise,
    > <c>false</c>.</value>
    > [Bindable(true)]
    > [Category("Callback")]
    > [Description("Whether this control uses callback functionality or
    > not.")]
    > public bool CallbackEnabled
    > {
    > get
    > {
    > bool b = (bool)ViewState["IsCallback"];
    > return b;
    > }
    > set
    > {
    > ViewState["IsCallback"] = value;
    > }
    > }
    >
    > /// <summary>
    > /// Gets or sets a value indicating whether this control is

    disabled
    > during callback.
    > /// </summary>
    > /// <value><c>true</c> if disabled during callback; otherwise,
    > <c>false</c>.</value>
    > [Bindable(true)]
    > [Category("Callback")]
    > [Description("Whether this control is disabled while a background
    > callback is in effect.")]
    > public bool DisableAtCallback
    > {
    > get
    > {
    > bool b = (bool)ViewState["DisableAtCallback"];
    > return b;
    > }
    > set
    > {
    > ViewState["DisableAtCallback"] = value;
    > }
    > }
    >
    > /// <summary>
    > /// The location of the RadControls folder, containing the

    required
    > JavaScript support files.
    > /// </summary>
    > /// <value>The scripts path.</value>
    > [Bindable(true)]
    > [Category("Callback")]
    > [Description("The location of the RadControls folder, containing

    the
    > required JavaScript support files.")]
    > public string ScriptsPath
    > {
    > get
    > {
    > String s = (String)ViewState["ScriptsPath"];
    > return ((s == null) ? String.Empty : s);
    > }
    > set
    > {
    > Debug.Assert(value != null, "Warning: ScriptsPath property
    > is null!");
    > if (value != null)
    > {
    > ViewState["ScriptsPath"] = value;
    > }
    > else
    > {
    > throw new NullReferenceException("ScriptsPath can not

    be
    > assigned a null value.");
    > }
    > }
    > }
    >
    > /// <summary>
    > /// Gets or sets the position of the descriptive label relative to
    > the rest of the control.
    > /// </summary>
    > /// <value>The label position.</value>
    > [Bindable(true)]
    > [Category("Label")]
    > [DefaultValue(Position.Left)]
    > [Localizable(false)]
    > [Description("The position of the descriptive label relative to

    the
    > rest of the control.")]
    > public Position LabelPosition
    > {
    > get
    > {
    > Position p = (Position)ViewState["LabelPosition"];
    > return p;
    > }
    > set
    > {
    > ViewState["LabelPosition"] = value;
    > }
    > }
    >
    > /// <summary>
    > /// Gets or sets the text displayed in the descriptive label.
    > /// </summary>
    > /// <value>The label text.</value>
    > [Bindable(true)]
    > [Category("Label")]
    > [DefaultValue("")]
    > [Localizable(true)]
    > [Description("The text to display in the descriptive label.")]
    > public string LabelText
    > {
    > get
    > {
    > EnsureChildControls();
    > String s = (String)ViewState["LabelText"];
    > return ((s == null) ? String.Empty : s);
    > }
    > set
    > {
    > Debug.Assert(value != null, "Warning: LabelText property

    is
    > null!");
    > if (value != null)
    > {
    > ViewState["LabelText"] = value;
    > }
    > else
    > {
    > throw new NullReferenceException("LabelText can not be
    > assigned a null value.");
    > }
    > }
    > }
    >
    > /// <summary>
    > /// Gets or sets the label text resource key.
    > /// </summary>
    > /// <value>The label text resource key.</value>
    > [Bindable(true)]
    > [Category("Label")]
    > [DefaultValue("")]
    > [Localizable(false)]
    > public string LabelTextResourceKey
    > {
    > get
    > {
    > String s = (String)ViewState["LabelTextResourceKey"];
    > return ((s == null) ? String.Empty : s);
    > }
    > set
    > {
    > Debug.Assert(value != null, "Warning: LabelTextResourceKey
    > property is null!");
    > if (value != null)
    > {
    > ViewState["LabelTextResourceKey"] = value;
    > }
    > else
    > {
    > throw new NullReferenceException("LabelTextResourceKey
    > can not be assigned a null value.");
    > }
    > }
    > }
    >
    > /// <summary>
    > /// Gets or sets the label CSS class.
    > /// </summary>
    > /// <value>The label CSS class.</value>
    > [Bindable(true)]
    > [Category("Label")]
    > [DefaultValue("")]
    > [Localizable(false)]
    > public string LabelCssClass
    > {
    > get
    > {
    > string s = (string)ViewState["LabelTextCssClass"];
    > return (s == null) ? String.Empty : s;
    > }
    > set
    > {
    > Debug.Assert(value != null, "Warning: LabelCssClass

    property
    > is null!");
    > if (value != null)
    > {
    > ViewState["LabelTextCssClass"] = value;
    > }
    > else
    > {
    > throw new NullReferenceException("LabelTextCssClass

    can
    > not be assigned a null value.");
    > }
    > }
    > }
    >
    > /// <summary>
    > /// Gets or sets a value indicating whether label is visible.
    > /// </summary>
    > /// <value><c>true</c> if label is visible; otherwise,
    > <c>false</c>.</value>
    > [Bindable(true)]
    > [Category("Label")]
    > [DefaultValue(true)]
    > [Localizable(false)]
    > public bool LabelVisible
    > {
    > get
    > {
    > bool b = (bool)ViewState["LabelVisible"];
    > return (b);
    > }
    > set
    > {
    > ViewState["LabelVisible"] = value;
    > }
    > }
    >
    > /// <summary>
    > /// Gets or sets the width of the label.
    > /// </summary>
    > /// <value>The width of the label.</value>
    > [Bindable(true)]
    > [Category("Label")]
    > [Localizable(false)]
    > [Description("The width of the descriptive label.")]
    > public Unit LabelWidth
    > {
    > get
    > {
    > Unit u = (Unit)ViewState["LabelWidth"];
    > return (u);
    > }
    > set
    > {
    > Debug.Assert(value != null, "Warning: LabelWidth property

    is
    > null!");
    > ViewState["LabelWidth"] = value;
    > }
    > }
    >
    > /// <summary>
    > /// Gets or sets a value indicating whether the <see
    > cref="SupportFormLabelledControl"/> is required.
    > /// If required is set to true, than a validating <see
    > cref="IconPopupControl"/> will be added to this control.
    > /// </summary>
    > /// <value><c>true</c> if required; otherwise,

    <c>false</c>.</value>
    > [Bindable(true)]
    > [Category("Required")]
    > [DefaultValue(false)]
    > [Localizable(false)]
    > [Description("Determines whether the Required icon validator is
    > present on this control or not.")]
    > public bool Required
    > {
    > get
    > {
    > bool b = (bool)ViewState["Required"];
    > return (b);
    > }
    > set
    > {
    > ViewState["Required"] = value;
    > }
    > }
    >
    > /// <summary>
    > /// Gets or sets a value indicating whether to automatically post
    > back when the control is clicked.
    > /// </summary>
    > /// <value><c>true</c> if controls posts back when clicked;
    > otherwise, <c>false</c>.</value>
    > [Bindable(true)]
    > [Category("Behavior")]
    > [DefaultValue(typeof(bool), "False")]
    > [Description("Automatically posts back to the server when the
    > control is clicked.")]
    > [Localizable(false)]
    > public bool AutoPostback
    > {
    > get
    > {
    > bool b = (bool)ViewState["AutoPostBack"];
    > return b;
    > }
    > set
    > {
    > ViewState["AutoPostBack"] = value;
    > }
    > }
    >
    > /// <summary>
    > /// Gets or sets the URL of the image to display when
    > WarningIconVisible is set to true.
    > /// </summary>
    > /// <value>The warning image URL.</value>
    > [Bindable(false)]
    > [Category("Required")]
    > [Localizable(false)]
    > [Editor("System.Web.UI.Design.ImageUrlEditor, System.Design,
    > Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
    > typeof(UITypeEditor))]
    > [Description("The image to display when WarningIconVisible is set

    to
    > true.")]
    > public string WarningImageUrl
    > {
    > get
    > {
    > string s = (string)ViewState["WarningImageUrl"];
    > return (s == null) ? String.Empty : s;
    > }
    > set
    > {
    > Debug.Assert(value != null, "Warning: WarningImageUrl
    > property is null!");
    > if (value != null)
    > {
    > ViewState["WarningImageUrl"] = value;
    > }
    > else
    > {
    > throw new NullReferenceException("WarningImageUrl can
    > not be assigned a null value.");
    > }
    > }
    > }
    >
    > /// <summary>
    > /// Gets or sets the URL of the page to open when the required
    > icon's MessageStyle is set to UrlLink.
    > /// </summary>
    > /// <value>The link URL.</value>
    > [Bindable(false)]
    > [Category("Required")]
    > [Localizable(false)]
    > [Editor("System.Web.UI.Design.UrlEditor, System.Design,
    > Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
    > typeof(UITypeEditor))]
    > [Description("The URL of the page to open when the Required icon's
    > MessageStyle is set to UrlLink.")]
    > public string LinkUrl
    > {
    > get
    > {
    > string s = (string)ViewState["LinkUrl"];
    > return (s == null) ? String.Empty : s;
    > }
    > set
    > {
    > Debug.Assert(value != null, "Warning: LinkUrl property is
    > null!");
    > if (value != null)
    > {
    > ViewState["LinkUrl"] = value;
    > }
    > else
    > {
    > throw new NullReferenceException("LinkUrl can not be
    > assigned a null value.");
    > }
    > }
    > }
    >
    > /// <summary>
    > /// Gets or sets the type of message to display when the user

    clicks
    > or moves their mouse over the required icon.
    > /// </summary>
    > /// <value>The message style.</value>
    > [Bindable(false)]
    > [Category("Required")]
    > [Localizable(false)]
    > [DefaultValue(MessageStyle.NoMessage)]
    > [Description("The type of message to display when the user clicks

    or
    > moves their mouse over the Required icon.")]
    > public MessageStyle MessageStyle
    > {
    > get
    > {
    > MessageStyle m = (MessageStyle)ViewState["MessageStyle"];
    > return m;
    > }
    > set
    > {
    > ViewState["MessageStyle"] = value;
    > }
    > }
    >
    > /// <summary>
    > /// Gets or sets the body text to use in the popup window when
    > MessageStyle is set to PopupMessage.
    > /// </summary>
    > /// <value>The popup text.</value>
    > [Bindable(false)]
    > [Category("Required")]
    > [Localizable(true)]
    > [Description("The body text to use in the popup window when
    > MessageStyle is set to PopupMessage.")]
    > public string PopupText
    > {
    > get
    > {
    > string s = (string)ViewState["PopupText"];
    > return (s == null) ? String.Empty : s;
    > }
    > set
    > {
    > Debug.Assert(value != null, "Warning: PopupText property

    is
    > null!");
    > if (value != null)
    > {
    > ViewState["PopupText"] = value;
    > }
    > else
    > {
    > throw new NullReferenceException("PopupText can not be
    > assigned a null value.");
    > }
    > }
    > }
    >
    > /// <summary>
    > /// Gets or sets the resource key of the body text to use in the
    > popup window when MessageStyle is set to PopupMessage.
    > /// </summary>
    > /// <value>The popup text.</value>
    > [Bindable(false)]
    > [Category("Required")]
    > [Localizable(true)]
    > public string PopupTextResourceKey
    > {
    > get
    > {
    > string s = (string)ViewState["PopupTextResourceKey"];
    > return (s == null) ? String.Empty : s;
    > }
    > set
    > {
    > Debug.Assert(value != null, "Warning: PopupTextResourceKey
    > property is null!");
    > if (value != null)
    > {
    > ViewState["PopupTextResourceKey"] = value;
    > }
    > else
    > {
    > throw new NullReferenceException("PopupTextResourceKey
    > can not be assigned a null value.");
    > }
    > }
    > }
    >
    > /// <summary>
    > /// Gets or sets the title to use in the popup window when
    > MessageStyle is set to PopupMessage.
    > /// </summary>
    > /// <value>The popup title.</value>
    > [Bindable(false)]
    > [Category("Required")]
    > [Localizable(true)]
    > [Description("The title to use in the popup window when

    MessageStyle
    > is set to PopupMessage.")]
    > public string PopupTitle
    > {
    > get
    > {
    > string s = (string)ViewState["PopupTitle"];
    > return (s == null) ? String.Empty : s;
    > }
    > set
    > {
    > Debug.Assert(value != null, "Warning: PopupTitle property

    is
    > null!");
    > if (value != null)
    > {
    > ViewState["PopupTitle"] = value;
    > }
    > else
    > {
    > throw new NullReferenceException("PopupTitle can not

    be
    > assigned a null value.");
    > }
    > }
    > }
    >
    > #endregion
    > }
    > }
    >
     
    Axel Dahmen, Jan 16, 2006
    #2
    1. Advertising

  3. > Too big, I'm afraid. Who's supposed to read that??

    The problem I'm having is that no matter which value I assign to the
    LabelPosition property, it always returns the default value inside the
    CreateChildControls() method. I explicitly set it to Top, and this
    appears in the Html code behind, but it is always the default (Left) when I
    set
    and reach a breakpoint in CreateChildControls().
     
    Christophe Peillet, Jan 16, 2006
    #3
  4. Hi Christophe,

    As for the custom composite control's Property, are you setting it at
    design-time or programmatically set it at runtime? Generally we can try
    checking through the following things:

    1. If you're set the value through design-time interface, check the
    control's inline template in aspx page to see whether the design-time value
    is correctly persisted (through attribute or inner property...)

    2. If you're setting it at runtime programmatically, it is very important
    that we set it at the proper time and also depend on our controls code. I
    don't think the SetDefaultProperties method you mentioned will cause the
    problem since it only apply the default values in Control's constructor
    where other events hasn't taken place (though you can also comment it to
    confirm this...).

    What you can pay more attention is whether the property you set is
    correctly stored in the ViewState so that when post back or page reload the
    control is able to retrieve it back again... It is possible that the
    property value is not correctly persisted in viewstate so that next time
    the control reload state from Viewstate, it is not correctly set.

    Also, instead of debugging the control code, you can consider using the
    Page's Output Trace to write out some statements in your custom control's
    code (e.g the CreateChildControl, property 's set accesor.... and any other
    methods or events which related to the problem), the Output Trace will be
    displayed through the Trace table on page according to the occuring time.
    This will be very helpful for throubleshooting such issue..

    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.)







    --------------------
    | Thread-Topic: CreateChildControls() always returns default property values
    | thread-index: AcYZA5YuDerg4WGhQ3uPEG8oxWA5Ig==
    | X-WBNR-Posting-Host: 82.236.3.78
    | From: =?Utf-8?B?Q2hyaXN0b3BoZSBQZWlsbGV0?=
    <>
    | Subject: CreateChildControls() always returns default property values
    | Date: Sat, 14 Jan 2006 04:11:02 -0800
    | Lines: 833
    | Message-ID: <>
    | MIME-Version: 1.0
    | Content-Type: text/plain;
    | charset="Utf-8"
    | Content-Transfer-Encoding: 7bit
    | X-Newsreader: Microsoft CDO for Windows 2000
    | Content-Class: urn:content-classes:message
    | Importance: normal
    | Priority: normal
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
    | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
    | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGXA03.phx.gbl
    | Xref: TK2MSFTNGXA02.phx.gbl
    microsoft.public.dotnet.framework.aspnet.webcontrols:32468
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    |
    | I am trying to develop a composite control that renders in a specific
    layout,
    | depending on the value of the custom LabelPosition property. The
    'layout' of
    | the rendered control will change depending on whether the value of
    | LabelPosition is set to Left, Right, Top, or Bottom, as can be seen in
    the
    | CreateChildControls() method.
    |
    | This particular class (included below) actually acts as a base class for
    | many other controls (such as a textbox, checkbox, datepicker, etc.), so
    not
    | all of the logic is implemented here. Because I don't know what objects
    will
    | need to be added by the child controls (textbox, etc.), I have inserted a
    | PlaceHolder control in the appropriate section of the table, and child
    | controls insert their own objects here. (This allows me to keep the code
    for
    | rendering the table in the parent class, making code maintenance much
    easier
    | for me if changes are ever needed.)
    |
    | The problem I'm having is that no matter which value I assign to the
    | LabelPosition property, it always returns the default value inside the
    | CreateChildControls() method. I explicitly set it to Top, and this
    appears
    | in the Html code behind, but it is always the default (Left) when I set
    and
    | reach a breakpoint in CreateChildControls().
    |
    | I'm sure my problem is that I have not properly understood the composite
    | control page model, and am setting default values in the wrong place
    (look at
    | the SetDefaultValues() method reference in the constructor), or am
    creating
    | the table in the wrong place (based on the 'switch' in
    | CreateChildControls()). Or, the problem could be something with
    ViewState,
    | that I am not properly storing/refreshing the value of the LabelPosition
    | property.
    |
    | If anyone can help me understand why this value is not being restored,
    and
    | always reads as default, I would enormously appreciate it, since I've
    spend
    | many hours on this to no avail, including a lot of time on Google.
    |
    | The base class is included below. If you need the Designer class (which
    | contains nothing exotic) or a child class (that implements this base
    class),
    | let me know any I'll post it.
    |
    | PS: Because of maximum message length, I have trimmed some unneccessary
    | properties from the code.
    |
    | using System;
    | using System.Collections.Generic;
    | using System.Text;
    | using System.Web;
    | using System.Web.UI;
    | using System.Web.UI.WebControls;
    | using System.ComponentModel;
    | using System.ComponentModel.Design;
    | using System.Diagnostics;
    | using System.Drawing.Design;
    | using Telerik.WebControls;
    |
    | namespace CompanyName.EEE.Web.UI.FormControls
    | {
    | /// <summary>
    | /// The BaseClass used in all of CompanyName's form custom form
    controls
    | which require a descriptive label.
    | /// </summary>
    | // [Designer(typeof(SupportFormLabelledControlDesigner))]
    | [DefaultProperty("LabelText")]
    | [ToolboxData("<{0}:SupportFormLabelledControl
    | runat=\"server\"></{0}:SupportFormLabelledControl>")]
    | public abstract class SupportFormLabelledControl :
    SupportFormControl,
    | INamingContainer, ICallback, IRequired
    | {
    |
    | #region Protected Fields
    |
    | // Any third-party or external controls that you wish to add to
    the
    | this
    | // control, such as buttons, labels, etc., should be declared
    here.
    | By
    | // declaring them 'protected' they will be visible in any control
    that
    | // inherits from SupportFormLabelledControl
    |
    | /// <summary>The Table used to hold child controls on the
    | form</summary>
    | protected Table m_tbl;
    | /// <summary>The CallbackLabel rendered with the control</summary>
    | protected CallbackLabel m_lbl;
    | /// <summary>The Warning Icon rendered with the control when <see
    | cref="P:Required"/> is set to <c>true</c></summary>
    | protected IconPopupControl m_icn;
    | /// <summary>The content PlaceHolder used to insert any child
    | controls that need to be added (Textboxes, Checkboxes, etc).</summary>
    | protected PlaceHolder m_plc;
    |
    | #endregion
    |
    | #region Constructor
    |
    | // Default values for properties should ONLY be defined in the the
    | // class constructor. If you set properties elsewhere, such as
    in the
    | // OnLoad event, you will make the control insensitive to
    external,
    | // tag-level settings.
    |
    | /// <summary>
    | /// Initializes a new instance of the <see
    | cref="SupportFormLabelledControl"/> class.
    | /// </summary>
    | public SupportFormLabelledControl()
    | {
    | // Set control default values
    | this.SetDefaultValues();
    | }
    |
    | #endregion
    |
    | #region Abstract Members
    |
    | /// <summary>
    | /// If the control's Required property is set to True, this
    method
    | can be
    | /// used to validate whether the Required conditions are met or
    not.
    | /// </summary>
    | /// <returns>
    | /// <c>true</c> if the Required conditions are met, <c>false</c>
    if
    | they are not.
    | /// </returns>
    | public abstract bool ValidateControl();
    |
    | #endregion
    |
    | #region Protected Methods
    |
    | /// <summary>
    | /// Raises the <see cref="E:System.Web.UI.Control.Init"></see>
    event.
    | /// </summary>
    | /// <param name="e">An <see cref="T:System.EventArgs"></see>
    object
    | that contains the event data.</param>
    | protected override void OnInit(EventArgs e)
    | {
    | base.OnInit(e);
    | }
    |
    | /// <summary>
    | /// Raises the <see cref="E:System.Web.UI.Control.Load"></see>
    event.
    | /// </summary>
    | /// <param name="e">The <see cref="T:System.EventArgs"></see>
    object
    | that contains the event data.</param>
    | protected override void OnLoad(EventArgs e)
    | {
    | // This method captures the controls Load event (declared and
    | bound in the
    | // class constructor). RunTime rendering takes place in this
    | method (as
    | // opposed to DesignMode rendering, which takes place
    elsewhere).
    |
    | // Call base Load method
    | base.OnLoad(e);
    |
    | EnsureChildControls();
    | }
    |
    | /// <summary>
    | /// Called by the ASP.NET page framework to notify server
    controls
    | that use
    | /// composition-based implementation to create any child controls
    | they contain
    | /// in preparation for posting back or rendering.
    | /// </summary>
    | protected override void CreateChildControls()
    | {
    | // Clear the control collection
    | Controls.Clear();
    |
    | // Any dependant controls used in this custom control must
    | // be added to the control 'hierarchy'. If they are not added
    | // to the control collection, they will not be visible to
    other
    | // controls on the page.
    |
    | // Instantiate any dependant controls
    | m_tbl = new Table();
    | m_lbl = new CallbackLabel();
    | m_icn = new IconPopupControl();
    | m_plc = new PlaceHolder();
    |
    | // Create table object and format it through relevant method
    | m_tbl =
    | SharedFunctions.CreateLabelledControlTable(this.LabelPosition);
    |
    | // Add table to the control collection
    | Controls.Add(m_tbl);
    |
    | // Add controls to the table control collection
    | switch (this.LabelPosition)
    | {
    | case Position.Left:
    | m_tbl.Rows[0].Cells[0].Controls.Add(m_lbl);
    | m_tbl.Rows[0].Cells[1].Controls.Add(m_plc);
    | m_tbl.Rows[0].Cells[1].Controls.Add(m_icn);
    | // Set relevant design properties
    | m_tbl.Rows[0].Cells[0].Width = new
    | Unit(this.LabelWidth.ToString());
    | break;
    | case Position.Top:
    | m_tbl.Rows[0].Cells[0].Controls.Add(m_lbl);
    | m_tbl.Rows[1].Cells[0].Controls.Add(m_plc);
    | m_tbl.Rows[1].Cells[0].Controls.Add(m_icn);
    | // Set relevant design properties
    | m_tbl.Rows[0].Cells[0].Width = new
    | Unit(this.LabelWidth.ToString());
    | break;
    | case Position.Right:
    | m_tbl.Rows[0].Cells[0].Controls.Add(m_plc);
    | m_tbl.Rows[0].Cells[0].Controls.Add(m_icn);
    | m_tbl.Rows[0].Cells[1].Controls.Add(m_lbl);
    | // Set relevant design properties
    | m_tbl.Rows[0].Cells[1].Width = new
    | Unit(this.LabelWidth.ToString());
    | break;
    | case Position.Bottom:
    | m_tbl.Rows[0].Cells[0].Controls.Add(m_plc);
    | m_tbl.Rows[0].Cells[0].Controls.Add(m_icn);
    | m_tbl.Rows[1].Cells[0].Controls.Add(m_lbl);
    | // Set relevant design properties
    | m_tbl.Rows[1].Cells[0].Width = new
    | Unit(this.LabelWidth.ToString());
    | break;
    | default:
    | Debug.Assert(false);
    | break;
    | }
    |
    | // Call base method
    | base.CreateChildControls();
    | }
    |
    | protected override void OnPreRender(EventArgs e)
    | {
    | // Call base method
    | base.OnPreRender(e);
    |
    | // Associate dependent control properties with this control's
    | properties
    | m_lbl.CssClass = this.LabelCssClass;
    | m_lbl.Text = this.LabelText;
    | m_lbl.Visible = this.LabelVisible;
    | m_lbl.RadControlsDir = this.ScriptsPath;
    | m_lbl.CallbackEnabled = this.CallbackEnabled;
    | m_lbl.DisableAtCallback = this.DisableAtCallback;
    | m_lbl.Enabled = this.Enabled;
    | m_icn.WarningImageUrl = this.WarningImageUrl;
    | m_icn.ImageAlign = this.ImageAlign;
    | m_icn.EmptyImageUrl = this.EmptyImageUrl;
    | m_icn.MessageStyle = this.MessageStyle;
    | m_icn.PopupText = this.PopupText;
    | m_icn.PopupTextResourceKey = this.PopupTextResourceKey;
    | m_icn.PopupTitle = this.PopupTitle;
    | m_icn.PopupTitleResourceKey = this.PopupTitleResourceKey;
    | m_icn.LinkUrl = this.LinkUrl;
    | m_icn.Enabled = this.Enabled;
    | m_icn.CssClass = this.WarningIconCssStyle;
    |
    | // Enable or disable warning icon as appropriate
    | m_icn.Visible = this.Required ? true : false;
    | }
    |
    | #endregion
    |
    | #region Private/Internal Methods
    |
    | /// <summary>
    | /// Sets the control's default values.
    | /// </summary>
    | private void SetDefaultValues()
    | {
    | // Set default properties
    | this.LabelPosition = Position.Left;
    | this.LabelText = string.Empty;
    | this.LabelCssClass = SharedConstants.SupportForm_LabelStyle;
    | this.LabelVisible = true;
    | this.LabelWidth = new
    | Unit(SharedConstants.SupportForm_DefaultLabelWidth);
    | this.Required = false;
    | this.CallbackEnabled =
    | SharedConstants.SupportForm_CallbackEnabledByDefault;
    | this.DisableAtCallback =
    | SharedConstants.SupportForm_DisableAtCallback;
    | this.ScriptsPath =
    SharedConstants.SupportForm_DefaultScriptsPath;
    | this.AutoPostback = false;
    | this.ImageAlign = ImageAlign.AbsMiddle;
    | this.LinkUrl = string.Empty;
    | this.MessageStyle = MessageStyle.NoMessage;
    | this.PopupText = string.Empty;
    | this.PopupTextResourceKey = string.Empty;
    | this.PopupTitle = string.Empty;
    | this.PopupTitleResourceKey = string.Empty;
    | this.WarningIconVisible = false;
    | this.WarningIconCssStyle =
    | SharedConstants.SupportForm_WarningIconStyle;
    | this.WarningImageUrl =
    | SharedConstants.SupportForm_IconPopupControlDefaultWarningImageUrl;
    | this.EmptyImageUrl =
    | SharedConstants.SupportForm_IconPopupControlDefaultEmptyImageUrl;
    | }
    |
    | /// <summary>
    | /// Sets the design mode values.
    | /// </summary>
    | internal virtual void SetDesignModeValues()
    | {
    | // Ensure child controls are created
    | EnsureChildControls();
    |
    | // Associate dependent control properties with this control's
    | properties
    | m_lbl.CssClass = this.LabelCssClass;
    | m_lbl.Text = this.LabelText == string.Empty ? "[LabelText]" :
    | this.LabelText;
    | m_lbl.Visible = this.LabelVisible;
    | m_lbl.RadControlsDir = this.ScriptsPath;
    | m_lbl.CallbackEnabled = this.CallbackEnabled;
    | m_lbl.DisableAtCallback = this.DisableAtCallback;
    | m_lbl.Enabled = this.Enabled;
    | m_icn.WarningImageUrl = this.WarningImageUrl;
    | m_icn.ImageAlign = this.ImageAlign;
    | m_icn.EmptyImageUrl = this.EmptyImageUrl;
    | m_icn.MessageStyle = this.MessageStyle;
    | m_icn.PopupText = this.PopupText;
    | m_icn.PopupTextResourceKey = this.PopupTextResourceKey;
    | m_icn.PopupTitle = this.PopupTitle;
    | m_icn.PopupTitleResourceKey = this.PopupTitleResourceKey;
    | m_icn.LinkUrl = this.LinkUrl;
    | m_icn.WarningIconVisible = this.WarningIconVisible;
    | m_icn.Enabled = this.Enabled;
    | m_icn.CssClass = this.WarningIconCssStyle;
    | if (this.Required)
    | {
    | m_icn.Visible = true;
    | }
    | else
    | {
    | m_icn.Visible = false;
    | }
    | // For DesignMode, always display the warning icon
    | m_icn.WarningIconVisible = true;
    | }
    |
    | #endregion
    |
    | #region Public Properties
    |
    | /// <summary>
    | /// Gets or sets a value indicating whether this control uses
    AJAX
    | callback functionality or not.
    | /// </summary>
    | /// <value><c>true</c> if callback enabled; otherwise,
    | <c>false</c>.</value>
    | [Bindable(true)]
    | [Category("Callback")]
    | [Description("Whether this control uses callback functionality or
    | not.")]
    | public bool CallbackEnabled
    | {
    | get
    | {
    | bool b = (bool)ViewState["IsCallback"];
    | return b;
    | }
    | set
    | {
    | ViewState["IsCallback"] = value;
    | }
    | }
    |
    | /// <summary>
    | /// Gets or sets a value indicating whether this control is
    disabled
    | during callback.
    | /// </summary>
    | /// <value><c>true</c> if disabled during callback; otherwise,
    | <c>false</c>.</value>
    | [Bindable(true)]
    | [Category("Callback")]
    | [Description("Whether this control is disabled while a background
    | callback is in effect.")]
    | public bool DisableAtCallback
    | {
    | get
    | {
    | bool b = (bool)ViewState["DisableAtCallback"];
    | return b;
    | }
    | set
    | {
    | ViewState["DisableAtCallback"] = value;
    | }
    | }
    |
    | /// <summary>
    | /// The location of the RadControls folder, containing the
    required
    | JavaScript support files.
    | /// </summary>
    | /// <value>The scripts path.</value>
    | [Bindable(true)]
    | [Category("Callback")]
    | [Description("The location of the RadControls folder, containing
    the
    | required JavaScript support files.")]
    | public string ScriptsPath
    | {
    | get
    | {
    | String s = (String)ViewState["ScriptsPath"];
    | return ((s == null) ? String.Empty : s);
    | }
    | set
    | {
    | Debug.Assert(value != null, "Warning: ScriptsPath
    property
    | is null!");
    | if (value != null)
    | {
    | ViewState["ScriptsPath"] = value;
    | }
    | else
    | {
    | throw new NullReferenceException("ScriptsPath can not
    be
    | assigned a null value.");
    | }
    | }
    | }
    |
    | /// <summary>
    | /// Gets or sets the position of the descriptive label relative
    to
    | the rest of the control.
    | /// </summary>
    | /// <value>The label position.</value>
    | [Bindable(true)]
    | [Category("Label")]
    | [DefaultValue(Position.Left)]
    | [Localizable(false)]
    | [Description("The position of the descriptive label relative to
    the
    | rest of the control.")]
    | public Position LabelPosition
    | {
    | get
    | {
    | Position p = (Position)ViewState["LabelPosition"];
    | return p;
    | }
    | set
    | {
    | ViewState["LabelPosition"] = value;
    | }
    | }
    |
    | /// <summary>
    | /// Gets or sets the text displayed in the descriptive label.
    | /// </summary>
    | /// <value>The label text.</value>
    | [Bindable(true)]
    | [Category("Label")]
    | [DefaultValue("")]
    | [Localizable(true)]
    | [Description("The text to display in the descriptive label.")]
    | public string LabelText
    | {
    | get
    | {
    | EnsureChildControls();
    | String s = (String)ViewState["LabelText"];
    | return ((s == null) ? String.Empty : s);
    | }
    | set
    | {
    | Debug.Assert(value != null, "Warning: LabelText property
    is
    | null!");
    | if (value != null)
    | {
    | ViewState["LabelText"] = value;
    | }
    | else
    | {
    | throw new NullReferenceException("LabelText can not
    be
    | assigned a null value.");
    | }
    | }
    | }
    |
    | /// <summary>
    | /// Gets or sets the label text resource key.
    | /// </summary>
    | /// <value>The label text resource key.</value>
    | [Bindable(true)]
    | [Category("Label")]
    | [DefaultValue("")]
    | [Localizable(false)]
    | public string LabelTextResourceKey
    | {
    | get
    | {
    | String s = (String)ViewState["LabelTextResourceKey"];
    | return ((s == null) ? String.Empty : s);
    | }
    | set
    | {
    | Debug.Assert(value != null, "Warning:
    LabelTextResourceKey
    | property is null!");
    | if (value != null)
    | {
    | ViewState["LabelTextResourceKey"] = value;
    | }
    | else
    | {
    | throw new
    NullReferenceException("LabelTextResourceKey
    | can not be assigned a null value.");
    | }
    | }
    | }
    |
    | /// <summary>
    | /// Gets or sets the label CSS class.
    | /// </summary>
    | /// <value>The label CSS class.</value>
    | [Bindable(true)]
    | [Category("Label")]
    | [DefaultValue("")]
    | [Localizable(false)]
    | public string LabelCssClass
    | {
    | get
    | {
    | string s = (string)ViewState["LabelTextCssClass"];
    | return (s == null) ? String.Empty : s;
    | }
    | set
    | {
    | Debug.Assert(value != null, "Warning: LabelCssClass
    property
    | is null!");
    | if (value != null)
    | {
    | ViewState["LabelTextCssClass"] = value;
    | }
    | else
    | {
    | throw new NullReferenceException("LabelTextCssClass
    can
    | not be assigned a null value.");
    | }
    | }
    | }
    |
    | /// <summary>
    | /// Gets or sets a value indicating whether label is visible.
    | /// </summary>
    | /// <value><c>true</c> if label is visible; otherwise,
    | <c>false</c>.</value>
    | [Bindable(true)]
    | [Category("Label")]
    | [DefaultValue(true)]
    | [Localizable(false)]
    | public bool LabelVisible
    | {
    | get
    | {
    | bool b = (bool)ViewState["LabelVisible"];
    | return (b);
    | }
    | set
    | {
    | ViewState["LabelVisible"] = value;
    | }
    | }
    |
    | /// <summary>
    | /// Gets or sets the width of the label.
    | /// </summary>
    | /// <value>The width of the label.</value>
    | [Bindable(true)]
    | [Category("Label")]
    | [Localizable(false)]
    | [Description("The width of the descriptive label.")]
    | public Unit LabelWidth
    | {
    | get
    | {
    | Unit u = (Unit)ViewState["LabelWidth"];
    | return (u);
    | }
    | set
    | {
    | Debug.Assert(value != null, "Warning: LabelWidth property
    is
    | null!");
    | ViewState["LabelWidth"] = value;
    | }
    | }
    |
    | /// <summary>
    | /// Gets or sets a value indicating whether the <see
    | cref="SupportFormLabelledControl"/> is required.
    | /// If required is set to true, than a validating <see
    | cref="IconPopupControl"/> will be added to this control.
    | /// </summary>
    | /// <value><c>true</c> if required; otherwise,
    <c>false</c>.</value>
    | [Bindable(true)]
    | [Category("Required")]
    | [DefaultValue(false)]
    | [Localizable(false)]
    | [Description("Determines whether the Required icon validator is
    | present on this control or not.")]
    | public bool Required
    | {
    | get
    | {
    | bool b = (bool)ViewState["Required"];
    | return (b);
    | }
    | set
    | {
    | ViewState["Required"] = value;
    | }
    | }
    |
    | /// <summary>
    | /// Gets or sets a value indicating whether to automatically post
    | back when the control is clicked.
    | /// </summary>
    | /// <value><c>true</c> if controls posts back when clicked;
    | otherwise, <c>false</c>.</value>
    | [Bindable(true)]
    | [Category("Behavior")]
    | [DefaultValue(typeof(bool), "False")]
    | [Description("Automatically posts back to the server when the
    | control is clicked.")]
    | [Localizable(false)]
    | public bool AutoPostback
    | {
    | get
    | {
    | bool b = (bool)ViewState["AutoPostBack"];
    | return b;
    | }
    | set
    | {
    | ViewState["AutoPostBack"] = value;
    | }
    | }
    |
    | /// <summary>
    | /// Gets or sets the URL of the image to display when
    | WarningIconVisible is set to true.
    | /// </summary>
    | /// <value>The warning image URL.</value>
    | [Bindable(false)]
    | [Category("Required")]
    | [Localizable(false)]
    | [Editor("System.Web.UI.Design.ImageUrlEditor, System.Design,
    | Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
    | typeof(UITypeEditor))]
    | [Description("The image to display when WarningIconVisible is set
    to
    | true.")]
    | public string WarningImageUrl
    | {
    | get
    | {
    | string s = (string)ViewState["WarningImageUrl"];
    | return (s == null) ? String.Empty : s;
    | }
    | set
    | {
    | Debug.Assert(value != null, "Warning: WarningImageUrl
    | property is null!");
    | if (value != null)
    | {
    | ViewState["WarningImageUrl"] = value;
    | }
    | else
    | {
    | throw new NullReferenceException("WarningImageUrl can
    | not be assigned a null value.");
    | }
    | }
    | }
    |
    | /// <summary>
    | /// Gets or sets the URL of the page to open when the required
    | icon's MessageStyle is set to UrlLink.
    | /// </summary>
    | /// <value>The link URL.</value>
    | [Bindable(false)]
    | [Category("Required")]
    | [Localizable(false)]
    | [Editor("System.Web.UI.Design.UrlEditor, System.Design,
    | Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
    | typeof(UITypeEditor))]
    | [Description("The URL of the page to open when the Required
    icon's
    | MessageStyle is set to UrlLink.")]
    | public string LinkUrl
    | {
    | get
    | {
    | string s = (string)ViewState["LinkUrl"];
    | return (s == null) ? String.Empty : s;
    | }
    | set
    | {
    | Debug.Assert(value != null, "Warning: LinkUrl property is
    | null!");
    | if (value != null)
    | {
    | ViewState["LinkUrl"] = value;
    | }
    | else
    | {
    | throw new NullReferenceException("LinkUrl can not be
    | assigned a null value.");
    | }
    | }
    | }
    |
    | /// <summary>
    | /// Gets or sets the type of message to display when the user
    clicks
    | or moves their mouse over the required icon.
    | /// </summary>
    | /// <value>The message style.</value>
    | [Bindable(false)]
    | [Category("Required")]
    | [Localizable(false)]
    | [DefaultValue(MessageStyle.NoMessage)]
    | [Description("The type of message to display when the user clicks
    or
    | moves their mouse over the Required icon.")]
    | public MessageStyle MessageStyle
    | {
    | get
    | {
    | MessageStyle m = (MessageStyle)ViewState["MessageStyle"];
    | return m;
    | }
    | set
    | {
    | ViewState["MessageStyle"] = value;
    | }
    | }
    |
    | /// <summary>
    | /// Gets or sets the body text to use in the popup window when
    | MessageStyle is set to PopupMessage.
    | /// </summary>
    | /// <value>The popup text.</value>
    | [Bindable(false)]
    | [Category("Required")]
    | [Localizable(true)]
    | [Description("The body text to use in the popup window when
    | MessageStyle is set to PopupMessage.")]
    | public string PopupText
    | {
    | get
    | {
    | string s = (string)ViewState["PopupText"];
    | return (s == null) ? String.Empty : s;
    | }
    | set
    | {
    | Debug.Assert(value != null, "Warning: PopupText property
    is
    | null!");
    | if (value != null)
    | {
    | ViewState["PopupText"] = value;
    | }
    | else
    | {
    | throw new NullReferenceException("PopupText can not
    be
    | assigned a null value.");
    | }
    | }
    | }
    |
    | /// <summary>
    | /// Gets or sets the resource key of the body text to use in the
    | popup window when MessageStyle is set to PopupMessage.
    | /// </summary>
    | /// <value>The popup text.</value>
    | [Bindable(false)]
    | [Category("Required")]
    | [Localizable(true)]
    | public string PopupTextResourceKey
    | {
    | get
    | {
    | string s = (string)ViewState["PopupTextResourceKey"];
    | return (s == null) ? String.Empty : s;
    | }
    | set
    | {
    | Debug.Assert(value != null, "Warning:
    PopupTextResourceKey
    | property is null!");
    | if (value != null)
    | {
    | ViewState["PopupTextResourceKey"] = value;
    | }
    | else
    | {
    | throw new
    NullReferenceException("PopupTextResourceKey
    | can not be assigned a null value.");
    | }
    | }
    | }
    |
    | /// <summary>
    | /// Gets or sets the title to use in the popup window when
    | MessageStyle is set to PopupMessage.
    | /// </summary>
    | /// <value>The popup title.</value>
    | [Bindable(false)]
    | [Category("Required")]
    | [Localizable(true)]
    | [Description("The title to use in the popup window when
    MessageStyle
    | is set to PopupMessage.")]
    | public string PopupTitle
    | {
    | get
    | {
    | string s = (string)ViewState["PopupTitle"];
    | return (s == null) ? String.Empty : s;
    | }
    | set
    | {
    | Debug.Assert(value != null, "Warning: PopupTitle property
    is
    | null!");
    | if (value != null)
    | {
    | ViewState["PopupTitle"] = value;
    | }
    | else
    | {
    | throw new NullReferenceException("PopupTitle can not
    be
    | assigned a null value.");
    | }
    | }
    | }
    |
    | #endregion
    | }
    | }
    |
    |
     
    Steven Cheng[MSFT], Jan 16, 2006
    #4
  5. I'm setting this property at Design-Time ... normally it won't be modified at
    RunTime.

    I'm not sure it's a problem with the ViewState, since it also doesn't update
    when I modify it in the VS2005 IDE? For example, if I change the properties
    of the textbox, they update in the IDE, but not the LabelPosition property.
    In fact, all of the properties that are attached to child controls work
    properly (such as m_txt.Text, etc.). The properties that are not persisting
    are those that are not attached to any control (ex. this.LabelPosition). Do
    I need to be manually adding/loading these values from ViewState? Using
    Reflector, I've looked at several other controls, and see they often manually
    load/save the ViewState.

    I'll try seeing if I can find anything with trace, as you mentionned. Is
    there any easy way to debug controls in DesignMode, since it doesn't raise
    any break points you set unless you are in a RunTime environment?

    Thanks for your help on this (as well as an earlier issue I had).
     
    Christophe Peillet, Jan 16, 2006
    #5
  6. Steven:

    Having set some simple trace output, I get the below output. I've
    highlighted the relevant parts with '-->' arrows in front of the lines)

    I can see by these lines:
    aspx.page Begin Init 0.0103666806814833 0.001273
    --> Getting label position: Top 0.0178480784568989 0.007481
    --> Inside OnInit -- LabelPosition = : Top 0.0181165483322601 0.000268
    --> Getting label position: Left 0.0221265551906737 0.004010
    --> Inside OnInit -- LabelPosition = : Left 0.0223841298265562 0.000258

    That the control initially has the assigned LabelPostion value (Top), but
    for some reason it is quickly reset to the default in the same event (Init).
    I just don't see why this is. Any ideas why the same thing would be
    happening 3 times, and why it would reset the values from those requested in
    the HTML markup?

    C.

    Full Trace Output:
    =============================================
    Category Message From First(s) From Last(s)
    aspx.page Begin PreInit
    aspx.page End PreInit 0.00909361385315731 0.009094
    ---------------------------------------------------------
    aspx.page Begin Init 0.0103666806814833 0.001273
    --> Getting label position: Top 0.0178480784568989 0.007481
    --> Inside OnInit -- LabelPosition = : Top 0.0181165483322601 0.000268
    --> Getting label position: Left 0.0221265551906737 0.004010
    --> Inside OnInit -- LabelPosition = : Left 0.0223841298265562 0.000258
    --> Getting label position: Left 0.0228881044937276 0.000504
    --> Inside OnInit -- LabelPosition = : Left 0.0231275203971454 0.000239
    ----------------------------------------------------------
    aspx.page End Init 0.0249257936413706 0.001798
    aspx.page Begin InitComplete 0.0251688412912814 0.000243
    aspx.page End InitComplete 0.0258004858159347 0.000632
    aspx.page Begin PreLoad 0.0267285367274332 0.000928
    aspx.page End PreLoad 0.0296825434517515 0.002954
    ----------------------------------------------------------
    aspx.page Begin Load 0.0299300609434998 0.000248
    Getting label position: Top 0.0328592041725974 0.002929
    Inside OnLoad (before EnsureChildControls) -- LabelPosition = : Top
    0.0331145438875611 0.000255
    Getting label position: Top 0.0333159661353608 0.000201
    Inside OnLoad (after EnsureChildControls) -- LabelPosition = : Top
    0.0335123598110933 0.000196
    Getting label position: Left 0.0479784441877389 0.014466
    Inside OnLoad (before EnsureChildControls) -- LabelPosition = : Left
    0.0482399299352292 0.000261
    Getting label position: Left 0.0484388378969953 0.000199
    Inside OnLoad (after EnsureChildControls) -- LabelPosition = : Left
    0.0486335553820388 0.000195
    Getting label position: Left 0.061233760156668 0.012600
    Inside OnLoad (before EnsureChildControls) -- LabelPosition = : Left
    0.0614924522530098 0.000259
    Getting label position: Left 0.0616921983101204 0.000200
    Inside OnLoad (after EnsureChildControls) -- LabelPosition = : Left
    0.0618891507160826 0.000197
    ----------------------------------------------------------
    aspx.page End Load 0.0630295191148596 0.001140
    aspx.page Begin LoadComplete 0.0632725667647704 0.000243
    aspx.page End LoadComplete 0.0639117541475243 0.000639
    ----------------------------------------------------------
    aspx.page Begin PreRender 0.0643433732499522 0.000432
    Getting label position: Top 0.0714252789111465 0.007082
    Inside OnPreRender -- LabelPosition = Top 0.0716920725958187 0.000267
    Getting label position: Left 0.0997875428301642 0.028095
    Inside OnPreRender -- LabelPosition = Left 0.100053498419492 0.000266
    Getting label position: Left 0.191318729056347 0.091265
    Inside OnPreRender -- LabelPosition = Left 0.191579376708492 0.000261
    ----------------------------------------------------------
    aspx.page End PreRender 0.214891836811662 0.023312
    aspx.page Begin PreRenderComplete 0.216081373470651 0.001190
    aspx.page End PreRenderComplete 0.216978414854402 0.000897
    aspx.page Begin SaveState 0.294810653309289 0.077832
    aspx.page End SaveState 0.474743298380101 0.179933
    aspx.page Begin SaveStateComplete 0.474990536506735 0.000247
    aspx.page End SaveStateComplete 0.475634193731326 0.000644
    aspx.page Begin Render 0.475864669951069 0.000230
    aspx.page End Render
     
    Christophe Peillet, Jan 16, 2006
    #6
  7. ChildControlsCreated = False

    Steven:

    Working on this problem today, I noticed something. I have two 'types' of
    properties in my controls:

    1.) Properties that map to child controls
    2.) Properties that only pertain to the parent control itself.

    The properties that map directly to child controls properties (i.e.,
    'LabelText') work fine ... the problem is with the new/unique properties
    (i.e., 'LabelPosition', 'ScriptPath', etc.) that don't map anywhere.

    If I add the following line of code below to 'Set' statement in the unique
    properties, they work and render as expected:

    ....
    set
    {
    ....
    ViewState["LabelPosition"] = value;
    ChildControlsCreated = False;
    ....
    }
    ....

    However, this then causes all properties that map to to child control
    properties ('LabelText', etc.) NOT to work. Obviously I have screwed up the
    model somewhere, but I don't see where the problem is. This may have
    something to do with the inheritance model, as well. All of the
    unique/top-level properties are defined in a parent class
    (SupportFormLabelledControl), which creates a placeholder in the table. All
    child controls are actually created in a class that inherits from
    SupportFormLabelledControl, and adds the controls into the PlaceHolder added
    in the CreateChildControls() method of the parent. Just a thought that maybe
    there is a problem there?
     
    Christophe Peillet, Jan 16, 2006
    #7
  8. RE: ChildControlsCreated = False

    Hi Christophe,

    I've seen your new thread in the ASPNET groups and I've posted my reply and
    further suggestion in the below one:

    Subject: ViewState properties and mapped properties don't work well togethe
    Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols

    Please have a look there and feel free to post in that thread if you meet
    any further problem.

    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)





    --------------------
    | Thread-Topic: ChildControlsCreated = False
    | thread-index: AcYaq5Nf10sfhHNcQAS3i283vWSDWw==
    | X-WBNR-Posting-Host: 193.172.19.20
    | From: =?Utf-8?B?Q2hyaXN0b3BoZSBQZWlsbGV0?=
    <>
    | References: <>
    <>
    | Subject: ChildControlsCreated = False
    | Date: Mon, 16 Jan 2006 06:46:04 -0800
    | Lines: 35
    | Message-ID: <>
    | MIME-Version: 1.0
    | Content-Type: text/plain;
    | charset="Utf-8"
    | Content-Transfer-Encoding: 7bit
    | X-Newsreader: Microsoft CDO for Windows 2000
    | Content-Class: urn:content-classes:message
    | Importance: normal
    | Priority: normal
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
    | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
    | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGXA03.phx.gbl
    | Xref: TK2MSFTNGXA02.phx.gbl
    microsoft.public.dotnet.framework.aspnet.webcontrols:32503
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    |
    | Steven:
    |
    | Working on this problem today, I noticed something. I have two 'types'
    of
    | properties in my controls:
    |
    | 1.) Properties that map to child controls
    | 2.) Properties that only pertain to the parent control itself.
    |
    | The properties that map directly to child controls properties (i.e.,
    | 'LabelText') work fine ... the problem is with the new/unique properties
    | (i.e., 'LabelPosition', 'ScriptPath', etc.) that don't map anywhere.
    |
    | If I add the following line of code below to 'Set' statement in the
    unique
    | properties, they work and render as expected:
    |
    | ...
    | set
    | {
    | ....
    | ViewState["LabelPosition"] = value;
    | ChildControlsCreated = False;
    | ....
    | }
    | ...
    |
    | However, this then causes all properties that map to to child control
    | properties ('LabelText', etc.) NOT to work. Obviously I have screwed up
    the
    | model somewhere, but I don't see where the problem is. This may have
    | something to do with the inheritance model, as well. All of the
    | unique/top-level properties are defined in a parent class
    | (SupportFormLabelledControl), which creates a placeholder in the table.
    All
    | child controls are actually created in a class that inherits from
    | SupportFormLabelledControl, and adds the controls into the PlaceHolder
    added
    | in the CreateChildControls() method of the parent. Just a thought that
    maybe
    | there is a problem there?
    |
     
    Steven Cheng[MSFT], Jan 19, 2006
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Deryck
    Replies:
    4
    Views:
    526
    derek giroulle
    Jun 22, 2004
  2. =?Utf-8?B?QVNQIERldmVsb3Blcg==?=

    Enum returns wrong default values in a web service

    =?Utf-8?B?QVNQIERldmVsb3Blcg==?=, Aug 23, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    547
    =?Utf-8?B?QVNQIERldmVsb3Blcg==?=
    Aug 23, 2006
  3. Jonathan Wood
    Replies:
    2
    Views:
    4,273
    Jonathan Wood
    Feb 8, 2008
  4. DC
    Replies:
    0
    Views:
    753
  5. Christophe Peillet

    CreateChildControls() always has default values for properties

    Christophe Peillet, Jan 14, 2006, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    235
    Steven Cheng[MSFT]
    Jan 16, 2006
Loading...

Share This Page