A
Andrés Giraldo
Hi!
I'm trying to create a simple menu webcontrol, but I'm having problems
serializing the Items collection of the menu class, I'm using Visual Studio
..Net 2003 designer and when I draw the control, works fine, when I add
Items, works fine, but when I run it or when I pass from the HTML view to
the design view, it gives me the following error:
There's no property on Menu with the name of MenuItem.... ?????
How can I solve this?
I'm a little lost, I've already tried to implement a custom Designer,
Serializable() TAG Attributes, ParseChildre(True) Attribute, and now:
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
PersistenceMode(PersistenceMode.InnerDefaultProperty), Attributes... any
idea of how can I solve this?
Thanks a lot!
'***************************************************************************
***
Imports System.ComponentModel
#Region "Menu Class"
Public Class Menu
Inherits WebControl
Private _menuItemCollection As New MenuItemCollection
<DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _
PersistenceMode(PersistenceMode.InnerDefaultProperty)> _
Public ReadOnly Property Items() As MenuItemCollection
Get
Return _menuItemCollection
End Get
End Property
Public Sub AddItem(ByVal text As String, _
ByVal itemHeight As Integer, _
ByVal itemWidth As Integer)
Dim mitem As New MenuItem(text, itemHeight, itemWidth)
Items.Add(mitem)
End Sub
Public Sub AddItem(ByVal mitem As MenuItem)
Items.Add(mitem)
End Sub
Public Sub RemoveItem(ByVal index As Integer)
Items.Remove(index)
End Sub
Public Sub RemoveItem(ByVal id As String)
Items.Remove(id)
End Sub
Protected Overrides Sub AddParsedSubObject(ByVal obj As Object)
If (TypeOf obj Is MenuItem) Then
Me.Items.Add(CType(obj, MenuItem))
End If
End Sub
Protected Overrides Sub RenderContents(ByVal writer As
System.Web.UI.HtmlTextWriter)
Dim i As Integer
For i = 0 To Items.Count - 1
Controls.Add(Items.Item(i))
Items.Item(i).RenderControl(writer)
Next
End Sub
End Class
#End Region
#Region "MenuItemCollection Class"
Public Class MenuItemCollection
Inherits CollectionBase
Public ReadOnly Property Item(ByVal index As Integer) As MenuItem
Get
If ((index >= 0) And (index <= (Count - 1))) Then
Return CType(List.Item(index), MenuItem)
End If
End Get
End Property
Public ReadOnly Property Item(ByVal id As String) As MenuItem
Get
Dim i As Integer
For i = 0 To (List.Count - 1)
If (CType(List.Item(i), MenuItem).ID.ToUpper = id.ToUpper)
Then
Return CType(List.Item(i), MenuItem)
End If
Next
End Get
End Property
Public Sub Add(ByVal mitem As MenuItem)
List.Add(mitem)
End Sub
Public Function Contains(ByVal mitem As MenuItem) As Boolean
Return list.Contains(mitem)
End Function
Public Sub CopyTo(ByVal array() As MenuItem, _
ByVal index As Integer)
List.CopyTo(array, index)
End Sub
Public Function IndexOf(ByVal mitem As MenuItem) As Integer
Return List.IndexOf(mitem)
End Function
Public Sub Insert(ByVal index As Integer, _
ByVal mitem As MenuItem)
List.Insert(index, mitem)
End Sub
Public Sub Remove(ByVal index As Integer)
If ((index >= 0) And (index <= (Count - 1))) Then
List.RemoveAt(index)
End If
End Sub
Public Sub Remove(ByVal id As String)
Dim i As Integer
For i = 0 To (List.Count - 1)
If (CType(List.Item(i), MenuItem).ID.ToUpper = id.ToUpper) Then
List.RemoveAt(i)
Exit Sub
End If
Next
End Sub
Public Sub Remove(ByVal mitem As MenuItem)
List.Remove(mitem)
End Sub
End Class
#End Region
#Region "MenuItem"
<DefaultEvent("Click")> _
Public Class MenuItem
Inherits WebControl
Implements IPostBackEventHandler
Public Event Click As EventHandler
<Description("Devolución automática de datos al servidor después de
modificar el texto."), DefaultValue(False)> _
Public Property AutoPostBack() As Boolean
Get
If (CType(ViewState("_autoPostBack"), Object) Is Nothing) Then
ViewState("_autoPostBack") = False
End If
Return CType(ViewState("_autoPostBack"), Boolean)
End Get
Set(ByVal Value As Boolean)
ViewState("_autoPostBack") = Value
End Set
End Property
<Description("Valor del texto.")> _
Public Property Text() As String
Get
If (CType(ViewState("_Text"), Object) Is Nothing) Then
ViewState("_Text") = String.Empty
End If
Return CType(ViewState("_Text"), String)
End Get
Set(ByVal Value As String)
ViewState("_Text") = Value
End Set
End Property
Public Sub New()
InitVars("MenuItem")
End Sub
Public Sub New(ByVal itemText As String)
InitVars(itemText)
End Sub
Public Sub New(ByVal itemText As String, _
ByVal itemHeight As Integer, _
ByVal itemWidth As Integer)
InitVars(itemText, itemHeight, itemWidth)
End Sub
Public Sub RaisePostBackEvent(ByVal eventArgument As String) Implements
System.Web.UI.IPostBackEventHandler.RaisePostBackEvent
OnClick(New EventArgs)
End Sub
Public Overrides Sub RenderEndTag(ByVal writer As
System.Web.UI.HtmlTextWriter)
writer.Write(Text)
MyBase.RenderEndTag(writer)
End Sub
Private Sub InitVars( _
ByVal itemText As String, _
Optional ByVal itemHeight As Integer = 15, _
Optional ByVal itemWidth As Integer = 70)
BackColor = Color.FromArgb(255, 241, 241, 241)
Font.Name = "MS Sans Serif"
Font.Size = FontUnit.Parse("10")
Text = itemText
End Sub
Protected Overridable Sub OnClick(ByVal e As EventArgs)
RaiseEvent Click(Me, e)
End Sub
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
Dim script As New System.Text.StringBuilder
script.Append("<script language=javascript ")
script.Append("src='TYJCMI2.js'></script>")
Page.RegisterStartupScript("MenuItem", script.ToString)
Attributes("onMouseDown") = Attributes("onMouseDown") & _
";" & _
"chItem(this, " & _
"'default', " & _
"'#999999', '#999999')"
Attributes("onMouseOver") = Attributes("onMouseOver") & _
";" & _
"chItem(this, 'hand', " & _
"'#919191', '#f1f1f1')"
Attributes("onMouseOut") = Attributes("onMouseOut") & _
";" & "chItem(this, " & _
"'default', " & _
"'#f1f1f1', '#f1f1f1')"
Style.Add("border", "#f1f1f1 1px solid")
If (AutoPostBack) Then
Attributes("onClick") = Attributes("onClick") & ";" &
Page.GetPostBackEventReference(Me)
End If
MyBase.OnLoad(e)
End Sub
End Class
#End Region
I'm trying to create a simple menu webcontrol, but I'm having problems
serializing the Items collection of the menu class, I'm using Visual Studio
..Net 2003 designer and when I draw the control, works fine, when I add
Items, works fine, but when I run it or when I pass from the HTML view to
the design view, it gives me the following error:
There's no property on Menu with the name of MenuItem.... ?????
How can I solve this?
I'm a little lost, I've already tried to implement a custom Designer,
Serializable() TAG Attributes, ParseChildre(True) Attribute, and now:
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
PersistenceMode(PersistenceMode.InnerDefaultProperty), Attributes... any
idea of how can I solve this?
Thanks a lot!
'***************************************************************************
***
Imports System.ComponentModel
#Region "Menu Class"
Public Class Menu
Inherits WebControl
Private _menuItemCollection As New MenuItemCollection
<DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _
PersistenceMode(PersistenceMode.InnerDefaultProperty)> _
Public ReadOnly Property Items() As MenuItemCollection
Get
Return _menuItemCollection
End Get
End Property
Public Sub AddItem(ByVal text As String, _
ByVal itemHeight As Integer, _
ByVal itemWidth As Integer)
Dim mitem As New MenuItem(text, itemHeight, itemWidth)
Items.Add(mitem)
End Sub
Public Sub AddItem(ByVal mitem As MenuItem)
Items.Add(mitem)
End Sub
Public Sub RemoveItem(ByVal index As Integer)
Items.Remove(index)
End Sub
Public Sub RemoveItem(ByVal id As String)
Items.Remove(id)
End Sub
Protected Overrides Sub AddParsedSubObject(ByVal obj As Object)
If (TypeOf obj Is MenuItem) Then
Me.Items.Add(CType(obj, MenuItem))
End If
End Sub
Protected Overrides Sub RenderContents(ByVal writer As
System.Web.UI.HtmlTextWriter)
Dim i As Integer
For i = 0 To Items.Count - 1
Controls.Add(Items.Item(i))
Items.Item(i).RenderControl(writer)
Next
End Sub
End Class
#End Region
#Region "MenuItemCollection Class"
Public Class MenuItemCollection
Inherits CollectionBase
Public ReadOnly Property Item(ByVal index As Integer) As MenuItem
Get
If ((index >= 0) And (index <= (Count - 1))) Then
Return CType(List.Item(index), MenuItem)
End If
End Get
End Property
Public ReadOnly Property Item(ByVal id As String) As MenuItem
Get
Dim i As Integer
For i = 0 To (List.Count - 1)
If (CType(List.Item(i), MenuItem).ID.ToUpper = id.ToUpper)
Then
Return CType(List.Item(i), MenuItem)
End If
Next
End Get
End Property
Public Sub Add(ByVal mitem As MenuItem)
List.Add(mitem)
End Sub
Public Function Contains(ByVal mitem As MenuItem) As Boolean
Return list.Contains(mitem)
End Function
Public Sub CopyTo(ByVal array() As MenuItem, _
ByVal index As Integer)
List.CopyTo(array, index)
End Sub
Public Function IndexOf(ByVal mitem As MenuItem) As Integer
Return List.IndexOf(mitem)
End Function
Public Sub Insert(ByVal index As Integer, _
ByVal mitem As MenuItem)
List.Insert(index, mitem)
End Sub
Public Sub Remove(ByVal index As Integer)
If ((index >= 0) And (index <= (Count - 1))) Then
List.RemoveAt(index)
End If
End Sub
Public Sub Remove(ByVal id As String)
Dim i As Integer
For i = 0 To (List.Count - 1)
If (CType(List.Item(i), MenuItem).ID.ToUpper = id.ToUpper) Then
List.RemoveAt(i)
Exit Sub
End If
Next
End Sub
Public Sub Remove(ByVal mitem As MenuItem)
List.Remove(mitem)
End Sub
End Class
#End Region
#Region "MenuItem"
<DefaultEvent("Click")> _
Public Class MenuItem
Inherits WebControl
Implements IPostBackEventHandler
Public Event Click As EventHandler
<Description("Devolución automática de datos al servidor después de
modificar el texto."), DefaultValue(False)> _
Public Property AutoPostBack() As Boolean
Get
If (CType(ViewState("_autoPostBack"), Object) Is Nothing) Then
ViewState("_autoPostBack") = False
End If
Return CType(ViewState("_autoPostBack"), Boolean)
End Get
Set(ByVal Value As Boolean)
ViewState("_autoPostBack") = Value
End Set
End Property
<Description("Valor del texto.")> _
Public Property Text() As String
Get
If (CType(ViewState("_Text"), Object) Is Nothing) Then
ViewState("_Text") = String.Empty
End If
Return CType(ViewState("_Text"), String)
End Get
Set(ByVal Value As String)
ViewState("_Text") = Value
End Set
End Property
Public Sub New()
InitVars("MenuItem")
End Sub
Public Sub New(ByVal itemText As String)
InitVars(itemText)
End Sub
Public Sub New(ByVal itemText As String, _
ByVal itemHeight As Integer, _
ByVal itemWidth As Integer)
InitVars(itemText, itemHeight, itemWidth)
End Sub
Public Sub RaisePostBackEvent(ByVal eventArgument As String) Implements
System.Web.UI.IPostBackEventHandler.RaisePostBackEvent
OnClick(New EventArgs)
End Sub
Public Overrides Sub RenderEndTag(ByVal writer As
System.Web.UI.HtmlTextWriter)
writer.Write(Text)
MyBase.RenderEndTag(writer)
End Sub
Private Sub InitVars( _
ByVal itemText As String, _
Optional ByVal itemHeight As Integer = 15, _
Optional ByVal itemWidth As Integer = 70)
BackColor = Color.FromArgb(255, 241, 241, 241)
Font.Name = "MS Sans Serif"
Font.Size = FontUnit.Parse("10")
Text = itemText
End Sub
Protected Overridable Sub OnClick(ByVal e As EventArgs)
RaiseEvent Click(Me, e)
End Sub
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
Dim script As New System.Text.StringBuilder
script.Append("<script language=javascript ")
script.Append("src='TYJCMI2.js'></script>")
Page.RegisterStartupScript("MenuItem", script.ToString)
Attributes("onMouseDown") = Attributes("onMouseDown") & _
";" & _
"chItem(this, " & _
"'default', " & _
"'#999999', '#999999')"
Attributes("onMouseOver") = Attributes("onMouseOver") & _
";" & _
"chItem(this, 'hand', " & _
"'#919191', '#f1f1f1')"
Attributes("onMouseOut") = Attributes("onMouseOut") & _
";" & "chItem(this, " & _
"'default', " & _
"'#f1f1f1', '#f1f1f1')"
Style.Add("border", "#f1f1f1 1px solid")
If (AutoPostBack) Then
Attributes("onClick") = Attributes("onClick") & ";" &
Page.GetPostBackEventReference(Me)
End If
MyBase.OnLoad(e)
End Sub
End Class
#End Region