P
philaphan80
Hello. I'm still rather new to building custom controls, so please be
gentle.
What I'd like to be able to do, when validating, is drop my
CustomServerValidator (see below) and a generic Label control onto the
page. Then, all I'd have to do is set two properties:
ControlToValidate and my custom ErrorLabel. The custom control would
handle the rest at runtime, including sending the appropriate error
message to the Label tied to ErrorLabel.
I'd like the ErrorLabel property to act similarly to the
ControlToValidate property. When I choose ErrorLabel in the Properties
window, I'd like to see a dropdown filled with a list of objects -- in
this case, of type Label -- currently available on the form.
This is where the error occurs. The dropdown works properly, but if I
choose one of the labels, I get the following error message in Design
mode:
------------------------------------------------------------------------------------------------------------------------
Error Rendering Control - CustomServerValidator1
An unhandled exception has occurred.
Cannot create an object of type 'System.Web.UI.WebControls.Label' from
its string representation 'Label1' for the 'ErrorLabel' property.
------------------------------------------------------------------------------------------------------------------------
If I change the ErrorLabel property to type String, the error
disappears, but then I have to enter the Label's name manually.
How would I go about fixing this?
Also, one follow-up question.........
Because the CustomValidator derives from type Label, all of my
CustomServerValidators show up in the Properties dropdown list as well.
Once the issue above is fixed, is there any way to further "filter"
the dropdown to show only *pure* Label controls?
Thanks in advance!
Public Class CustomServerValidator
Inherits System.Web.UI.WebControls.CustomValidator
Private _ErrorLabel As Label
<Browsable(True)> _
Public Property ErrorLabel() As Label
Get
Return _ErrorLabel
End Get
Set(ByVal value As Label)
_ErrorLabel = value
End Set
End Property
Public Sub New()
Me.EnableClientScript = False
Me.ValidateEmptyText = True
End Sub
<...unrelated code removed...>
End Class
gentle.
What I'd like to be able to do, when validating, is drop my
CustomServerValidator (see below) and a generic Label control onto the
page. Then, all I'd have to do is set two properties:
ControlToValidate and my custom ErrorLabel. The custom control would
handle the rest at runtime, including sending the appropriate error
message to the Label tied to ErrorLabel.
I'd like the ErrorLabel property to act similarly to the
ControlToValidate property. When I choose ErrorLabel in the Properties
window, I'd like to see a dropdown filled with a list of objects -- in
this case, of type Label -- currently available on the form.
This is where the error occurs. The dropdown works properly, but if I
choose one of the labels, I get the following error message in Design
mode:
------------------------------------------------------------------------------------------------------------------------
Error Rendering Control - CustomServerValidator1
An unhandled exception has occurred.
Cannot create an object of type 'System.Web.UI.WebControls.Label' from
its string representation 'Label1' for the 'ErrorLabel' property.
------------------------------------------------------------------------------------------------------------------------
If I change the ErrorLabel property to type String, the error
disappears, but then I have to enter the Label's name manually.
How would I go about fixing this?
Also, one follow-up question.........
Because the CustomValidator derives from type Label, all of my
CustomServerValidators show up in the Properties dropdown list as well.
Once the issue above is fixed, is there any way to further "filter"
the dropdown to show only *pure* Label controls?
Thanks in advance!
Public Class CustomServerValidator
Inherits System.Web.UI.WebControls.CustomValidator
Private _ErrorLabel As Label
<Browsable(True)> _
Public Property ErrorLabel() As Label
Get
Return _ErrorLabel
End Get
Set(ByVal value As Label)
_ErrorLabel = value
End Set
End Property
Public Sub New()
Me.EnableClientScript = False
Me.ValidateEmptyText = True
End Sub
<...unrelated code removed...>
End Class