|
分類:[ASP.NET (VB)]
またまたお世話になります。
.netフレームワーク 1.1
VS2003
ASP.NET(VB)
Webカスタムコントロールでプロパティに設定した
パラメータが保存されません。
標準のコンボボックスなどの場合には
<asp:DropDownList id="DropDownList1" style="Z-INDEX: 101; LEFT: 432px; POSITION: absolute; TOP: 216px"
runat="server" Width="184px" Height="120px">
<asp:ListItem Value="aaa">aaa</asp:ListItem>
<asp:ListItem Value="bbb">bbb</asp:ListItem>
<asp:ListItem Value="ccc">ccc</asp:ListItem>
</asp:DropDownList>
などと保存されますが、
自分で作成したクラスではプロパティが保存されませんでした。
設定したプロパティを保存する方法はありませんか?
下記、自分で作成したクラスのソース
Public Class MyControl
Inherits System.Web.UI.WebControls.WebControl
Protected _mControlData1 As New ControlData
<Bindable(True), Category("Appearance"), DefaultValue("")> Public Property ControlData1() As ControlData
Get
Return _mControlData1
End Get
Set(ByVal Value As ControlData)
_mControlData1 = Value
End Set
End Property
・・・
End Class
<Serializable(), _
TypeConverter(GetType(ControlDataConverter))> _
Public Class ControlData
Protected _mTitle As String
Protected _mDataList As New ArrayList
Public Property Title() As String
Get
Return _mTitle
End Get
Set(ByVal Value As String)
_mTitle = Value
End Set
End Property
<Editor(GetType(ControlDataEditor), GetType(UITypeEditor))> _
Public Property DataList() As ArrayList
Get
Return _mDataList
End Get
Set(ByVal Value As ArrayList)
_mDataList = Value
End Set
End Property
End Class
Public Class ControlDataConverter
Inherits ExpandableObjectConverter
Public Overloads Overrides Function CanConvertTo( _
ByVal context As ITypeDescriptorContext, _
ByVal destinationType As Type) As Boolean
If destinationType Is GetType(ControlData) Then
Return True
End If
Return MyBase.CanConvertTo(context, destinationType)
End Function
Public Overloads Overrides Function ConvertTo( _
ByVal context As ITypeDescriptorContext, _
ByVal culture As System.Globalization.CultureInfo, _
ByVal value As Object, _
ByVal destinationType As Type) As Object
If destinationType Is GetType(String) And TypeOf value Is ControlData Then
Dim gd As ControlData = CType(value, ControlData)
Dim bf As New BinaryFormatter
Dim ms As New MemoryStream
bf.Serialize(ms, gd)
Return BitConverter.ToString(ms.ToArray)
End If
Return MyBase.ConvertTo(context, culture, value, destinationType)
End Function
Public Overloads Overrides Function CanConvertFrom( _
ByVal context As ITypeDescriptorContext, _
ByVal sourceType As Type) As Boolean
If sourceType Is GetType(String) Then
Return True
End If
Return MyBase.CanConvertFrom(context, sourceType)
End Function
Public Overloads Overrides Function ConvertFrom( _
ByVal context As ITypeDescriptorContext, _
ByVal culture As System.Globalization.CultureInfo, _
ByVal value As Object) As Object
If TypeOf value Is String Then
Dim hexChars As String() = value.ToString().Split(New Char() {"-"c})
Dim gd As New ControlData
Dim bf As New BinaryFormatter
Dim ms As New MemoryStream
Dim i As Integer
For i = 0 To UBound(hexChars)
ms.WriteByte(Convert.ToByte(hexChars(i), 16))
Next
gd = CType(bf.Deserialize(ms), ControlData)
Return gd
End If
Return MyBase.ConvertFrom(context, culture, value)
End Function
End Class
Public Class ControlDataEditor
Inherits CollectionEditor
Public Sub New(ByVal type As System.Type)
MyBase.New(type)
End Sub
Protected Overloads Overrides Function CanSelectMultipleInstances() As Boolean
Return False
End Function
Protected Overloads Overrides Function CreateCollectionItemType() As System.Type
Return GetType(ControlDataPoint)
End Function
Protected Overloads Overrides Function CreateInstance(ByVal itemType As System.Type) As Object
If itemType Is GetType(ControlDataPoint) Then
Return New ControlDataPoint
End If
Return Nothing
End Function
End Class
<Serializable()> _
Public Class ControlDataPoint
Protected _mX As String
Protected _mY As Decimal
Public Property X() As String
Get
Return _mX
End Get
Set(ByVal Value As String)
_mX = Value
End Set
End Property
Public Property Y() As Decimal
Get
Return _mY
End Get
Set(ByVal Value As Decimal)
_mY = Value
End Set
End Property
End Class
|