Asked by:
Override CssClass property

Question
-
User-1821120043 posted
I am creating a "disabled" linkbutton control where the developer can specify a "DisabledCssClass". I am trying to override the CssClass property to return the "DisabledCssClass" string instead of the CssClass (when applicable). Problem seems to be that the Get never gets called to execute the code...even when i explicitly call it. Any ideas? Here is my code
Public Overrides Property CssClass() As String Get If Me.Enabled Then Return MyBase.CssClass Else If Not Me.DisabledCssClass = String.Empty Then Return Me.DisabledCssClass Else Return MyBase.CssClass End If End If Return MyBase.CssClass End Get Set(ByVal value As String) MyBase.CssClass = value End Set End Property
Tuesday, March 18, 2008 12:19 AM
All replies
-
User1817629870 posted
Hmmm....I think you defined the propert perfectly but the cssclass property that is getting called is from the base class and not your custom control class. I faced this situation whne i was overriding the text property. Use the shadows keyword to hide the base class property and to ensure that your property gets called.
the example is listed below
the text marked in bold is important
Public Shadows Property Text() As String
Get
Return GetText()
End Get
Set(ByVal value As String)
SetText(value) 'calling some utility function to set the text
End Set
End PropertyTuesday, March 18, 2008 4:08 AM -
User-1821120043 posted
Excellent. I don't use Shadows very much, so completely forgot about it.
Tuesday, March 18, 2008 9:53 AM -
User-1821120043 posted
Well, that didn't work either. I changed Overrides to Shadows and still the Get isn't being called. The Set is still getting called. Is this something to do with how the control renders? Is it possible that when it goes to add the cssclass, it is calling some other method? The funny thing is that I am overriding the text property in the same control and it works great.
Tuesday, March 18, 2008 10:17 AM -
User1817629870 posted
hmmm...sounds surprising
If its going in the set it should also o in the get.
Can u confirm if the enabled property is coming false and code does not go in the "if me.enabled" sectionWednesday, March 19, 2008 12:59 AM