A
Andrei Sinelnikov
Hi,
I'm trying to build TextBox based custom web control. Part of this
control is shadowed CssClass property:
<Description("Choose Css property from the list.") _
, DefaultValue(GetType(CssType), "RequiredInput") _
, TypeConverter(GetType(EnumConverter))> _
Public Shadows Property CssClass() As CssType
Get
If MyBase.CssClass = "" Then
' If MyBase.CssClass empty - retrieve default value
for this property
' and assign it to the MyBase.CssClass.
Dim attributes As AttributeCollection =
TypeDescriptor.GetProperties(Me)("CssClass").Attributes
Dim myAttribute As DefaultValueAttribute =
CType(attributes(GetType(DefaultValueAttribute)),
DefaultValueAttribute)
MyBase.CssClass = [Enum].Parse(GetType(CssType),
myAttribute.Value)
End If
Return [Enum].Parse(GetType(CssType), MyBase.CssClass)
End Get
Set(ByVal Value As CssType)
MyBase.CssClass = [Enum].GetName(GetType(CssType), Value)
End Set
End Property
Enum CssType As Integer
UnDefined
Input
RequiredInput
DisabledInput
DependentInput
RequiredInputNoBorder
Data
End Enum
I know that I can add any design-time Custom Control attributes to the
the ToolboxData attribute in the class declaration area (in the
following example you can see CssClass='DisabledInput'):
<DefaultProperty("Text"), _
Designer("Solution.WebControls.Design.TextBoxWithValidationDesigner"),
_
ToolboxData("<{0}:TextBoxWithValidation
id='utxtTextBoxWithValidation' runat='server'
CssClass='DisabledInput'></{0}:TextBoxWithValidation>")> _
Public Class TextBoxWithValidation
Inherits System.Web.UI.WebControls.TextBox
'........
End Class
QUESTION:
How can I force control to render some (or even all) properties with
their predefined default values?
In other words: Let's say that I have 2 properties: CssClass and Text.
Default Value for the CssClass - DefaultValue(GetType(CssType),
"RequiredInput")
Default Value for the Text - DefaultValue("Type here...")
I want to leave class declaration ToolboxData attribute
"properties-free":
<DefaultProperty("Text"), _
Designer("Solution.WebControls.Design.TextBoxWithValidationDesigner"),
_
ToolboxData("<{0}:TextBoxWithValidation
id='utxtTextBoxWithValidation'
runat='server'></{0}:TextBoxWithValidation>")> _
Public Class TextBoxWithValidation
Inherits System.Web.UI.WebControls.TextBox
'........
End Class
But as soon as I drug&drop control from the toolbox to the page I want
to see in HTML following code:
<AS:TextBoxWithValidation id="utxtTextBoxWithValidation"
runat="server" CssClass="RequiredInput" Text="Type
here..."></AS:TextBoxWithValidation>
Any ideas?
Thank you in regards,
Andrei Sinelnikov
I'm trying to build TextBox based custom web control. Part of this
control is shadowed CssClass property:
<Description("Choose Css property from the list.") _
, DefaultValue(GetType(CssType), "RequiredInput") _
, TypeConverter(GetType(EnumConverter))> _
Public Shadows Property CssClass() As CssType
Get
If MyBase.CssClass = "" Then
' If MyBase.CssClass empty - retrieve default value
for this property
' and assign it to the MyBase.CssClass.
Dim attributes As AttributeCollection =
TypeDescriptor.GetProperties(Me)("CssClass").Attributes
Dim myAttribute As DefaultValueAttribute =
CType(attributes(GetType(DefaultValueAttribute)),
DefaultValueAttribute)
MyBase.CssClass = [Enum].Parse(GetType(CssType),
myAttribute.Value)
End If
Return [Enum].Parse(GetType(CssType), MyBase.CssClass)
End Get
Set(ByVal Value As CssType)
MyBase.CssClass = [Enum].GetName(GetType(CssType), Value)
End Set
End Property
Enum CssType As Integer
UnDefined
Input
RequiredInput
DisabledInput
DependentInput
RequiredInputNoBorder
Data
End Enum
I know that I can add any design-time Custom Control attributes to the
the ToolboxData attribute in the class declaration area (in the
following example you can see CssClass='DisabledInput'):
<DefaultProperty("Text"), _
Designer("Solution.WebControls.Design.TextBoxWithValidationDesigner"),
_
ToolboxData("<{0}:TextBoxWithValidation
id='utxtTextBoxWithValidation' runat='server'
CssClass='DisabledInput'></{0}:TextBoxWithValidation>")> _
Public Class TextBoxWithValidation
Inherits System.Web.UI.WebControls.TextBox
'........
End Class
QUESTION:
How can I force control to render some (or even all) properties with
their predefined default values?
In other words: Let's say that I have 2 properties: CssClass and Text.
Default Value for the CssClass - DefaultValue(GetType(CssType),
"RequiredInput")
Default Value for the Text - DefaultValue("Type here...")
I want to leave class declaration ToolboxData attribute
"properties-free":
<DefaultProperty("Text"), _
Designer("Solution.WebControls.Design.TextBoxWithValidationDesigner"),
_
ToolboxData("<{0}:TextBoxWithValidation
id='utxtTextBoxWithValidation'
runat='server'></{0}:TextBoxWithValidation>")> _
Public Class TextBoxWithValidation
Inherits System.Web.UI.WebControls.TextBox
'........
End Class
But as soon as I drug&drop control from the toolbox to the page I want
to see in HTML following code:
<AS:TextBoxWithValidation id="utxtTextBoxWithValidation"
runat="server" CssClass="RequiredInput" Text="Type
here..."></AS:TextBoxWithValidation>
Any ideas?
Thank you in regards,
Andrei Sinelnikov