S
Sam Terburg - Emanon
I'm trying to create my own GridView with some addons.
I'm realising that by creating a placeholder with a GridView and
SQLDataSource in it.
The problem is dat the fields defined in the DataFieldControlCollection
gets instantiated twice with which the second instantiation doesn't have
any attribute/property set.
Here is my code:
<phaFramework:EditGrid
id = "E01"
query = "SELECT bla FROM bla"
runat = "Server" >
<Fields>
<phaForm:frwNumericField
ID = "percentage"
HeaderText = "Percentage">
<validators>
<phaValidator:frwNumericValidator
minimalValue = 0
maximumValue = 10 />
</validators>
</phaForm:frwNumericField>
</Fields>
</phaFramework:EditGrid>
Public Class EditGrid
Inherits PlaceHolder
Friend WithEvents baseGridView As New GridView
Friend WithEvents baseDataSource As New SqlDataSource
Public Sub New()
Me.Controls.Add(Me.baseGridView)
Me.Controls.Add(Me.baseDataSource)
End Sub
Public ReadOnly Property Fields() As FormFieldCollection
Get
If ViewState("Fields") Is Nothing Then
ViewState("Fields") = New FormFieldCollection(Me)
End If
Return ViewState("Fields")
End Get
End Property
End Class
Public Class FormFieldCollection
Inherits List(Of iFormField)
End Class
Public Class frwTextField
Inherits TemplateField
Implements iFormField, IBindableTemplate
Protected arrValidators As New ValidatorCollection
Public ReadOnly Property validators() As ValidatorCollection
Get
Return Me.arrValidators
End Get
End Property
End Class
Public Class ValidatorCollection
Inherits List(Of BaseValidator)
End Class
Basicly that's it.
I have ofcourse simplified the code. It is mush more than this.
I've put logging (Trace) everythere and there i can see that the
frwNumericValidator is created and added to the List of validators.
When the Template of the field is instantiated (InstantiateIn called)
the validators collection is empty (count=0).
I can also see that the ValidatorCollection is created twice (the New
contstructor called twice).
what i think is that:
1) the FieldCollection is created by me with the New constructor
2) the FieldCollection is also created by restoring the ViewState.
And that in between the properties are set so that the second
instantiation doesn't have these properties set (these properties are
min/maxValues as can be seen as attributes of the aspx tag).
I've tried several options.
I've tried creating the FieldCollection as a StateManagedCollection
(like the GridView.columns). No success.
Can someone explain me how the .Net framework works?
What is it doing?
Sam.
I'm realising that by creating a placeholder with a GridView and
SQLDataSource in it.
The problem is dat the fields defined in the DataFieldControlCollection
gets instantiated twice with which the second instantiation doesn't have
any attribute/property set.
Here is my code:
<phaFramework:EditGrid
id = "E01"
query = "SELECT bla FROM bla"
runat = "Server" >
<Fields>
<phaForm:frwNumericField
ID = "percentage"
HeaderText = "Percentage">
<validators>
<phaValidator:frwNumericValidator
minimalValue = 0
maximumValue = 10 />
</validators>
</phaForm:frwNumericField>
</Fields>
</phaFramework:EditGrid>
Public Class EditGrid
Inherits PlaceHolder
Friend WithEvents baseGridView As New GridView
Friend WithEvents baseDataSource As New SqlDataSource
Public Sub New()
Me.Controls.Add(Me.baseGridView)
Me.Controls.Add(Me.baseDataSource)
End Sub
Public ReadOnly Property Fields() As FormFieldCollection
Get
If ViewState("Fields") Is Nothing Then
ViewState("Fields") = New FormFieldCollection(Me)
End If
Return ViewState("Fields")
End Get
End Property
End Class
Public Class FormFieldCollection
Inherits List(Of iFormField)
End Class
Public Class frwTextField
Inherits TemplateField
Implements iFormField, IBindableTemplate
Protected arrValidators As New ValidatorCollection
Public ReadOnly Property validators() As ValidatorCollection
Get
Return Me.arrValidators
End Get
End Property
End Class
Public Class ValidatorCollection
Inherits List(Of BaseValidator)
End Class
Basicly that's it.
I have ofcourse simplified the code. It is mush more than this.
I've put logging (Trace) everythere and there i can see that the
frwNumericValidator is created and added to the List of validators.
When the Template of the field is instantiated (InstantiateIn called)
the validators collection is empty (count=0).
I can also see that the ValidatorCollection is created twice (the New
contstructor called twice).
what i think is that:
1) the FieldCollection is created by me with the New constructor
2) the FieldCollection is also created by restoring the ViewState.
And that in between the properties are set so that the second
instantiation doesn't have these properties set (these properties are
min/maxValues as can be seen as attributes of the aspx tag).
I've tried several options.
I've tried creating the FieldCollection as a StateManagedCollection
(like the GridView.columns). No success.
Can someone explain me how the .Net framework works?
What is it doing?
Sam.