S
Stanley
Ok below is the code to my control with some code parts removed to keep this
post from being a novel. My problem is at this point I can add new items
from my collection and remove them via teh GUI designer at design time but
the information I put in at that time is not persisted to runtime. What am I
doing wrong?
-Stanley
post from being a novel. My problem is at this point I can add new items
from my collection and remove them via teh GUI designer at design time but
the information I put in at that time is not persisted to runtime. What am I
doing wrong?
-Stanley
Code:
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Drawing.Design
Imports System.Web.UI
<ToolboxData("<{0}:myControl runat=server></{0}:myControl>"), _
Designer(GetType(c)), _
PersistChildren(False), _
ParseChildren(False), _
DefaultProperty("Buttons")> _
Public Class myControl
Inherits System.Web.UI.Control
Private _buttons As ButtonCollection
<Editor(GetType(myCollectionEditor), GetType(UITypeEditor)),
NotifyParentProperty(True),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
PersistenceMode(PersistenceMode.InnerDefaultProperty)> _
Public ReadOnly Property Buttons() As ButtonCollection
Get
If _buttons Is Nothing Then
_buttons = New ButtonCollection
End If
Return _buttons
End Get
End Property
Protected Overrides Sub Render(ByVal output As
System.Web.UI.HtmlTextWriter)
Me.EnsureChildControls()
Me.RenderChildren(output)
End Sub
Protected Overrides Sub CreateChildControls()
Dim script As New System.Text.StringBuilder
'==================================
' Code left out because of length
'==================================
If Not Page.IsClientScriptBlockRegistered(Me.ID.ToString &
"_myScript") Then
Page.RegisterClientScriptBlock(Me.ID.ToString & "_myScript",
script.ToString)
End If
Dim script1 As New System.Text.StringBuilder
'==================================
' Code left out because of length
'==================================
If Not Page.IsClientScriptBlockRegistered(Me.ID.ToString &
"_myStartup") Then
Page.RegisterClientScriptBlock(Me.ID.ToString & "_myStartup",
script1.ToString)
End If
Dim b As ButtonClass
If Not _buttons Is Nothing Then
For Each b In _buttons
If b.ButtonType = ButtonClass.ButtonTypes.Button Then
Dim _b As WebControls.Button =
CType(Page.FindControl(b.ButtonName), WebControls.Button)
_b.Attributes.Add("onclick", "Javascript:b=true;")
ElseIf b.ButtonType = ButtonClass.ButtonTypes.ImageButton
Then
Dim _b As WebControls.ImageButton =
CType(Page.FindControl(b.ButtonName), WebControls.ImageButton)
_b.Attributes.Add("onclick", "Javascript:b=true;")
ElseIf b.ButtonType = ButtonClass.ButtonTypes.LinkButton
Then
Dim _b As WebControls.LinkButton =
CType(Page.FindControl(b.ButtonName), WebControls.LinkButton)
_b.Attributes.Add("onclick", "Javascript:b=true;")
End If
Next
End If
End Sub
End Class
Public Class ButtonClass
'Inherits Control
Public Enum ButtonTypes
LinkButton
Button
ImageButton
End Enum
Private _id As String
Private _buttontype As ButtonTypes
Public Property ButtonName() As String
Get
Return _id
End Get
Set(ByVal Value As String)
_id = Value
End Set
End Property
Public Property ButtonType() As ButtonTypes
Get
Return _buttontype
End Get
Set(ByVal Value As ButtonTypes)
_buttontype = Value
End Set
End Property
End Class
Public Class ButtonCollection
Inherits CollectionBase
Private _buttons As ArrayList
Friend Sub New()
If _buttons Is Nothing Then
_buttons = New ArrayList
End If
End Sub
Public ReadOnly Property Button(ByVal nIndex As Integer)
Get
Return CType(_buttons(nIndex), ButtonClass)
End Get
End Property
Public Sub Add(ByVal button As ButtonClass)
_buttons.Add(button)
End Sub
Public Function IndexOf(ByVal button As ButtonClass)
Return _buttons.IndexOf(button)
End Function
End Class
Public Class myCollectionEditor
Inherits CollectionEditor
Public Sub New(ByVal type As Type)
MyBase.New(type)
End Sub
Protected Overrides Function CreateCollectionItemType() As Type
Return GetType(ButtonClass)
End Function
End Class
Public Class myControl_Designer
Inherits System.Web.UI.Design.ControlDesigner
Protected Overrides Function GetEmptyDesignTimeHtml() As String
Dim strHtml As String
'==================================
' Code left out because of length
'==================================
Return strHtml
End Function
Public Overrides Function GetDesignTimeHtml() As String
Dim strHtml As String
'==================================
' Code left out because of length
'==================================
Return strHtml
End Function
End Class