I’m trying to work on a sub-class of System.Web.UI.WebControls.HyperLink in C# and I want to be able to specify a default text property that will replace the text value in certain conditions.
public class MyHyperLink : HyperLink
{
public string DefaultText { get; set; }
public override string Text
{
get
{
return string.IsNullOrEmpty(base.Text)
? (this.DefaultText ?? string.Empty)
: base.Text;
}
}
}
When I used this code my hyperlink rendered on the page but instead of <a>Default Text</a> I got <a text="Default Text"></a>.
According to reflector, you did miss an attribute, and did not override the setter