views:

23

answers:

1

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; 
        }
    }
A: 

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;}
}
Mike
I haven't explained myself properly, Lets say I've setup a property called SortBY in a similar way to the msdn example above. When my control is being used by a programmer they would type SortBy="???" - how would they know what the options are? In this case the options are 'Date' or 'Title' but I don't know how to give the programmer those options
insanepaul
SortByVar is kind of a dumb name for the enum but I think that is what you mean.
Mike
hi, thanks for the reply, I was thinking of using enum too but unsure how to fit it in to the composite control property. I've added some code to my original question to give you an idea if it helps.
insanepaul
While this improves readability of the composite control code does it provide intellisense for the person that uses the composite control?
insanepaul
Yes it will show up in the intellisense when the control is used. As for your code above you just want to make the get (SortBY)ViewState["SortBy"]. May want to make sure ViewState["SortBy"] isn't null first and return a default if it is.
Mike
Cool, that did it, I was hoping that would work but was going down some metadata route
insanepaul