Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Still having collection issues

Reply
Thread Tools

Still having collection issues

 
 
Stanley
Guest
Posts: n/a
 
      02-02-2004
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

 
Reply With Quote
 
 
 
 
gozza
Guest
Posts: n/a
 
      02-03-2004
Just a guess here?

[ParseChildren(true, "Buttons")]

gozza

"Stanley" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>
>



 
Reply With Quote
 
 
 
 
Stanley
Guest
Posts: n/a
 
      02-03-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Just a guess here?
>
> [ParseChildren(true, "Buttons")]
>
> gozza
>
> "Stanley" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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
> > 

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Řyvind Isaksen ASP .Net 1 05-18-2007 09:24 AM
Still having incomplete XML writing issues darrel ASP .Net 0 05-04-2006 06:33 PM
Still having multiple master browser issues. =?Utf-8?B?UmVjb24=?= Wireless Networking 0 01-25-2006 05:00 PM
I am getting a little further, but still having issues... Brent White ASP .Net 8 10-26-2005 06:04 PM
Still working on my collection issues Stanley ASP .Net Building Controls 0 02-04-2004 05:31 PM



Advertisments