The following code snippet can be used to web part custom properties
using System;
using System.ComponentModel;
using System.Text.RegularExpressions;
using System.Web.UI.WebControls.WebParts;
namespace WebPartProperties.VisualWebPart1
{
[ToolboxItemAttribute(false)]
public partial class VisualWebPart1 : WebPart
{
public VisualWebPart1()
{
_titles = "";
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
InitializeControl();
}
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = _titles + "</br>" + _eProperties + "</br>" + _list + "</br>" + _property;
}
//TextBox custom properties
private string _titles;
[WebBrowsable(true),
WebDisplayName("Title"),
WebDescription("Title Display"),
Personalizable(PersonalizationScope.Shared),
Category("TextBox Properties")]
public string MyTitleString
{
get { return _titles; }
set { _titles = value; }
}
//DropDownList custom properties
public enum EnumProperties
{
Property1,
Property2,
Property3
}
private EnumProperties _eProperties;
[Personalizable(),
WebBrowsable(true),
WebDisplayName("DropDown Property"),
Category("DropDownList Properties"),
WebDescription("Property description")]
public EnumProperties eProperties
{
get { return _eProperties; }
set { _eProperties = value; }
}
//ListItems custom properties
public enum siteLists
{
List1,
List2,
List3
};
protected siteLists _list;
[WebBrowsable(true),
WebDisplayName("Select the List"),
WebDescription(""),
Personalizable(PersonalizationScope.Shared),
Category("List Properties"),
DefaultValue("")]
public siteLists List
{
get { return _list; }
set { _list = value; }
}
//CheckBox custom properties
public Boolean _property;
[WebBrowsable(true),
WebDisplayName("Check box property"),
WebDescription(""),
Personalizable(
PersonalizationScope.Shared),
Category("Checkbox Properties"),
DefaultValue("")]
public Boolean _Property
{
get { return _property; }
set { _property = value; }
}
//Adding multiple controls in single category
public Boolean _property1;
[WebBrowsable(true),
WebDisplayName("Check box property1"),
WebDescription(""),
Personalizable(
PersonalizationScope.Shared),
Category("Checkbox Properties"),
DefaultValue("")]
public Boolean _Property1
{
get { return _property; }
set { _property = value; }
}
}
}
using System;
using System.ComponentModel;
using System.Text.RegularExpressions;
using System.Web.UI.WebControls.WebParts;
namespace WebPartProperties.VisualWebPart1
{
[ToolboxItemAttribute(false)]
public partial class VisualWebPart1 : WebPart
{
public VisualWebPart1()
{
_titles = "";
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
InitializeControl();
}
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = _titles + "</br>" + _eProperties + "</br>" + _list + "</br>" + _property;
}
//TextBox custom properties
private string _titles;
[WebBrowsable(true),
WebDisplayName("Title"),
WebDescription("Title Display"),
Personalizable(PersonalizationScope.Shared),
Category("TextBox Properties")]
public string MyTitleString
{
get { return _titles; }
set { _titles = value; }
}
//DropDownList custom properties
public enum EnumProperties
{
Property1,
Property2,
Property3
}
private EnumProperties _eProperties;
[Personalizable(),
WebBrowsable(true),
WebDisplayName("DropDown Property"),
Category("DropDownList Properties"),
WebDescription("Property description")]
public EnumProperties eProperties
{
get { return _eProperties; }
set { _eProperties = value; }
}
//ListItems custom properties
public enum siteLists
{
List1,
List2,
List3
};
protected siteLists _list;
[WebBrowsable(true),
WebDisplayName("Select the List"),
WebDescription(""),
Personalizable(PersonalizationScope.Shared),
Category("List Properties"),
DefaultValue("")]
public siteLists List
{
get { return _list; }
set { _list = value; }
}
//CheckBox custom properties
public Boolean _property;
[WebBrowsable(true),
WebDisplayName("Check box property"),
WebDescription(""),
Personalizable(
PersonalizationScope.Shared),
Category("Checkbox Properties"),
DefaultValue("")]
public Boolean _Property
{
get { return _property; }
set { _property = value; }
}
//Adding multiple controls in single category
public Boolean _property1;
[WebBrowsable(true),
WebDisplayName("Check box property1"),
WebDescription(""),
Personalizable(
PersonalizationScope.Shared),
Category("Checkbox Properties"),
DefaultValue("")]
public Boolean _Property1
{
get { return _property; }
set { _property = value; }
}
}
}
No comments:
Post a Comment