Rick,
I am pretty sure that I have posted you a reply about half an hour ago - but
since I cannot see it appearing I will try again:
Rick,
In fact, validators only list limited number of controls - and webcontrols
are definitely the ones they do not. The reason is relatively clear - the
internal structure of them is not known and can change.
I have not tested the following code in .Net 2.0, but I had it working in 1.1:
<TypeConverter(GetType(EnumConverter))> _
Public Overrides Property ControlToValidate As String
Get
If Me.Context Is Nothing Then
EnumConverter.defaultEnum = New
EnumConverter.StandardValuesCollection(getParentControlIDs(Me, True))
End If
Return CType(Me.ViewState("ControlToValidate"))
End Get
Set (ByVal Value As String)
Me.ViewState("ControlToValidate") = Value
End Set
then you need to define your converter:
Public Class EnumConverter
Inherits StringConverter
Public Shared defaultEnum As StandardValuesCollection
Public Overloads Overrides Function GetStandardValuesSupported(Byval
context As System.ComponentModel.ITypeDescriptionContext) As Boolean
Return True
End Function
Public Overloads Overrides Function GetStandardValues(ByVal context As
System.ComponentModel.ITypeDescriptionContext) As
System.ComponentModel.StandardValuesCollection
Return defaultEnum
End Function
End Class
then you need to define your function (in the same validator override)
Private Shared Function getParentControlIDs(ByVal control As Web.UI.Control)
as String()
Dim list As ArrayList = New ArrayList
For Each child As Web.Ui.Control In control.NamingContainer.Controls
If Not child.Equals(control) _
AndAlso Not TypeOf child Is BaseValidator _
AndAlso Not TypeOf child Is CustomValidator _
Then
' AndAlso Not TypeOf child Is Label / Literal, Button,
LinkButton, etc. - exclude as many as you think is appropriate
' alternatively you can specify the types of controls that you want
included - no solution is perfect
list.Add(child.ID)
End
Next
Dim result As String() = Ctype(Array.CreateInstance(GetType(String),
list.Count), String())
list.CopyTo(result)
Return result
End Function