I have a user control defined on an page as follows:
<uc:MyUserControl ID="MyUserControl" runat="server" Visible="true" />
I am wanting to reuse the same control on a different page with a custom property as follows:
<uc:MyUserControl ID="MyUserControl" runat="server" Visible="true"
MyCustomProperty="MyCustomText" />
The purpose of MyCustomProperty is to control some text in MyUserControl to be whatever I specify it to be.
For the first case I want the text to be "View" and for the second case I want it to be "MyCustomText".
In my user control I have the following code to define the property:
[DefaultValue("View")]
public string MyCustomProperty { get; set; }
I also have the following code to update the text based on the property:
LinkButton buttonSelect = e.Item.FindControl("ButtonSelect") as LinkButton;
if(buttonSelect != null) buttonSelect.Text = MyCustomProperty;
What actually happens is that when the custom property isn't supplied in the first case then MyCustomProperty == null.
I've tried to specify that the default should be "View" by adding the DefaultValue attribute but it hasn't had the affect that I intended.
Can anyone spot what I'm doing wrong?