Composite control property that allows coder to select from options
-
20-09-2019 - |
Question
The question is in the title but to make it clearer when you use a normal server control like
<asp:textbox />
<CC1:CtrlArticleList SortBy="Title" ID="compositeControlArticleList" runat="server" />
the properties of textbox allow you to select from a dropdown list (eg visibility=...true or false). How do I replicate this in composite control?
Added code since question asked:
Someone suggested using an enum but not sure how to set this up:
enum SortBY { Date, Title };
[Bindable(false), DefaultValue(""), Description("The sorting type of the DataPager")]
public SortBY SortBySomething
{
get
{
SortBY getDate = SortBY.Date;
if(getDate == (SortBY)ViewState["SortBy"])
{
return SortBY.Date;
}
else
{
return SortBY.Title;
}
}
set
{
ViewState["SortBy"] = value;
}
}
Solution
Just make them properties in your composite control like the example from MSDN below. Your public properties will then show up in the intellisence. If they don;t you may need to rebuild you app first.
public class Register : CompositeControl
{
private Button submitButton;
// The following properties are delegated to
// child controls.
[
Bindable(true),
Category("Appearance"),
DefaultValue(""),
Description("The text to display on the button.")
]
public string ButtonText
{
get
{
EnsureChildControls();
return submitButton.Text;
}
set
{
EnsureChildControls();
submitButton.Text = value;
}
}
After seeing your comment I think what you are looking for is (may not be perfect didn;t test but its close):
public enum SortType{Name,Date}
public SortType SortBy
{
get{
if(ViewState["SortBy"] != null){
return (SortType)ViewState["SortBy"];}
else{return SortType.Date;}
}
set{ViewState["SortBy"] = value;}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow