0

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; 
        }
    }
insanepaul
  • 187
  • 2
  • 5
  • 17
  • what do you mean by "the properties of textbox allow you to select from a dropdown list " ? – remi bourgarel Mar 16 '10 at 16:13
  • I mean some properties of a textbox in the design view allow us to select an option from a dropdownlist. For example typing 'runat=' automatically shows 'server'. I guess this is intellisense. I'm creating a composite control and I want the developer to set the SortBy property to either 'Date' or 'Title'. – insanepaul Mar 16 '10 at 16:22

1 Answers1

0

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
  • 5,437
  • 7
  • 45
  • 62
  • 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 Mar 16 '10 at 16:30
  • SortByVar is kind of a dumb name for the enum but I think that is what you mean. – Mike Mar 16 '10 at 16:35
  • 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 Mar 16 '10 at 16:55
  • While this improves readability of the composite control code does it provide intellisense for the person that uses the composite control? – insanepaul Mar 16 '10 at 17:00
  • 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 Mar 16 '10 at 17:13
  • Cool, that did it, I was hoping that would work but was going down some metadata route – insanepaul Mar 16 '10 at 17:43