Control cannot be created at design time

Discussion in 'ASP .Net Building Controls' started by Arthur Dzhelali, Dec 3, 2008.

  1. I am building fairly complex control
    and run into this problem.

    Error creating control [value] cannot be set on property [Property Name]

    If control dropped on the page it works fine property set and then page closed, then if page is reopened and any of the custom properties are set on
    the page I am getting this error from designer.


    So far I found two solutions



    1. Keep page open and restart VS
    2. Get out of designer into HTML and delete all properties of the control, then go back to designer and set them again.

    Additional information which might be helpful: my controls are inherited from CompositeControl

    I use Viewstate and SaveControlState functionality to save/restore properties



    http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=361826


    Thank you.

    Here is simplified version of the code:

    <ToolboxData("<{0}:MyTest runat='server' id='MyTest{0}'/>")> _
    Public Class MyTest
    Inherits CompositeControl
    <Category("Settings")> _
    <DefaultValue(" > ")> _
    <Description("Separator inserted between linkbuttons")> _
    Public Property Separator() As String
    Get

    If Me.ViewState("Separator") Is Nothing Then
    Return String.Empty
    End If
    Return ViewState("Separator")
    End Get
    Set(ByVal Value As String)

    Me.ViewState.Item("Separator") = Value
    Me.ChildControlsCreated = False
    End Set
    End Property


    Protected Overrides Function SaveControlState() As Object
    Return me.Separator
    End Function

    Protected Overrides Sub LoadControlState(ByVal savedState As Object)
    me.Separator = DirectCast(savedState, String)
    End Sub

    Private Sub Mytest_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
    If (Me.Page IsNot Nothing) Then Me.Page.RegisterRequiresControlState(Me)
    If Me.DesignMode Then
    Me.Width = New Unit(150, UnitType.Pixel)
    Me.Height= New Unit(30, UnitType.Pixel)
    Me.BackColor = Drawing.Color.AliceBlue
    End If
    End Sub

    Protected Overrides Sub CreateChildControls()
    ' Me.Controls.Clear()
    If Not Me.DesignMode Then
    ''Do Something
    SaveControlState()
    End If
    End If
    Me.ChildControlsCreated = True
    End Sub
    End Class
    Arthur Dzhelali, Dec 3, 2008
    #1
    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. Replies:
    0
    Views:
    709
  2. =?Utf-8?B?cm9iZXJ0bw==?=
    Replies:
    0
    Views:
    548
    =?Utf-8?B?cm9iZXJ0bw==?=
    Oct 25, 2004
  3. Replies:
    1
    Views:
    360
    Teemu Keiski
    Jul 2, 2003
  4. Amit Chawla
    Replies:
    2
    Views:
    226
    Amit Chawla
    Aug 23, 2004
  5. Replies:
    1
    Views:
    144
    James Britt
    Nov 24, 2005
Loading...

Share This Page