I've created custom properties for my user controls.
My user control:
<asp:PlaceHolder ID="BtnPlaceHolder" runat="server">
<asp:Button ID="Button1" runat="server" Text="Button1" PostBackUrl="~/Page1.aspx"/>
<asp:Button ID="Button2" runat="server" Text="Button2" PostBackUrl="~/Page2.aspx" />
</asp:PlaceHolder>
Property:
public bool ShouldBeVisible
{
get
{
return Button1.Visible;
}
set
{
Button1.Visible = value;
}
}
And in Page_Load:
protected void Page_Load(object sender, EventArgs e)
{
Button1.Visible = ShouldBeVisible;
}
In page1.aspx using the UC:
<uc:MyUserControl runat="server" />
If I want to use the property on another button (eg. Button2), how can I re-use the ShouldBeVisible property?
EDIT: Sorry, but the ShouldBeVisible property I want to use on the Buttons, not the UC declaration. Depending on which page (page or page2) I want to show Button1 or Button2.
return Button1.Visiblebut instead<uc:MyUserControl ID="MyUC" associatedControl="Button2" />and then in codereturn AssociatedControl.Visible?