Control cannot be created at design time

  • Thread starter Arthur Dzhelali
  • Start date
A

Arthur Dzhelali

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,056
Messages
2,570,443
Members
47,090
Latest member
LillieRipl

Latest Threads

Top