How to Create custom property in WEB-USER-CONTROL(.ascx)

I am going to expain in this article how create custom properties in webuser controls, where you need to pass a value from your .aspx page to the user control (.ascx). This is possible in several ways but the easiest way is to create a properties of the user control and set it into the .aspx page and access it from the user control

<PV:PremiumVenues ID="PremiumVenues" IsVisible="true" runat="server"></PV:PremiumVenues>

web-usercontrols source code -

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
public partial class CustomPropertiese : System.Web.UI.UserControl
{
    private Boolean vp_visible = false;
 
    # region Properties
 
    public Boolean IsVisible
    {
        get { return vp_visible; }
        set { vp_visible = value; }
    }
 
    #endregion Properties
 
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.Visible = IsVisible;
        }
    }
}

 

Comments (3) -

Good Article

Administrator 6/30/2017 6:54:56 PM

Thanks for reading the blogs

Administrator 7/28/2017 10:04:00 PM

You are welcome

Add comment