Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Building Controls (http://www.velocityreviews.com/forums/f59-asp-net-building-controls.html)
-   -   Still having collection issues (http://www.velocityreviews.com/forums/t756417-still-having-collection-issues.html)

Stanley 02-02-2004 02:54 PM

Still having collection issues
 
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

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



gozza 02-03-2004 01:10 AM

Re: Still having collection issues
 
Just a guess here?

[ParseChildren(true, "Buttons")]

gozza

"Stanley" <webmaster@nospam-glass-images.com> wrote in message
news:e8qWexZ6DHA.3804@tk2msftngp13.phx.gbl...
> 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
>
>
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
>

>
>




Stanley 02-03-2004 12:51 PM

Re: Still having collection issues
 
Tried that and I still am having the problem. The basic idea is that I can
click on the elipses in the designer to add the ID of buttons on my page
that I want the attributes changed. I also have it so that they can pick
from 3 different types which are LinkButton, Button and ImageButton. Then
when the control renders it will look on the page and find those buttons and
add the attribute to them. Does anyone have some source code to work with
collections like this in a custom control? I just need to look at an example
to see where I am going wrong. Or perhaps a tutorial? Over a week of
searching and I havn't found one yet.

TIA

-Stanley

"gozza" <someone@microsoft.com> wrote in message
news:OFZJPKf6DHA.2656@TK2MSFTNGP11.phx.gbl...
> Just a guess here?
>
> [ParseChildren(true, "Buttons")]
>
> gozza
>
> "Stanley" <webmaster@nospam-glass-images.com> wrote in message
> news:e8qWexZ6DHA.3804@tk2msftngp13.phx.gbl...
> > 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
> >
> >
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),
> >

Code:

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


> >
> >

>
>





All times are GMT. The time now is 12:42 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.