User-649410219 posted
You can use the code bellow.
If you need keep saved the data you set into properties, you may use ViewState or ControlState.
This, you must overrides the methods that control the state.
[ToolboxData("<{0}:MyCustomButton runat=\"server\"></{0}:MyCustomButton>")]
public class MyCustomButton : System.Web.UI.WebControls.Button
{
private string _MyCustomProperty;
public string MyCustomProperty
{
get{ return _MyCustomProperty; }
set{ _MyCustomProperty = value; }
}
//save the control state
protected override object SaveControlState()
{
//your code here
}
//load the control state
protected override void LoadControlState(object savedState)
{
//your code here
}
}
Or, you may use the ViewState.
[ToolboxData("<{0}:MyCustomButton runat=\"server\"></{0}:MyCustomButton>")]
public class MyCustomButton : System.Web.UI.WebControls.Button
{
private string _MyCustomProperty;
public string MyCustomProperty
{
get{ if(ViewState["MyCustomProperty"] != null) return ViewState["MyCustomProperty"].ToString(); else return string.Empty; }
set{ ViewState.Add("MyCustomProperty", value); }
}
}
When you generate your control's assembly (dll), in ToolBox Tab you add it. And then, very easy, drag'n drop!
I hope it helps u!