Custom User Controls - Abstraction..?

Last post 07-31-2009 11:17 AM by DD85. 2 replies.

Sort Posts:

  • Custom User Controls - Abstraction..?

    07-31-2009, 7:00 AM
    • Member
      286 point Member
    • DD85
    • Member since 07-15-2009, 10:27 AM
    • Posts 105

    Hi,

    What level of abstraction do you generally aim for when using / creating custom user controls? For example, if you made a navigation control comprised of image button controls with appropriate logic to set one image button at a time to appear highlighted (via changing the image source), how deeply would you aim to hard code it? Can you specify constructors for custom controls? It would be awesome to be able to pass an array of link values or an XML file to some navigation control and have it create the appropriate number of buttons, keeping the logic to select a button on a click event. It would be nice to be able to specify the selected / deselected image sources to. The result would be a totally reusable, abstracted control. Obviously it wouldn't be hard to just create a single instance, but that's not what I'm getting at.

    Any thoughts..?

    Dim MyAnswer As Answer = New Answer()
    Dim CorrectAnswer As Answer = New Answer()
    If MyAnswer = CorrectAnswer Then
    MarkAsAnswer(MyAnswer)
    Thank(Me)
    End If
  • Re: Custom User Controls - Abstraction..?

    07-31-2009, 8:21 AM
    Answer
    • All-Star
      36,240 point All-Star
    • rtpHarry
    • Member since 10-01-2006, 12:51 PM
    • Lincoln, England
    • Posts 5,827

    You could use a public property to allow you to specify a property to set an xml file path or a List<> object for a datasource.

    Add something like this into your code behind

    public string XmlDataPath { get; set; }

    and then you could set it as an attribute in the markup like

    <cc1:YourControl runat="server" ID="YourControl1" XmlDataPath="~/Example/Path.xml" />


    or edit in via code like

    YourControl1.XmlDataPath = "~/Example/Path.xml";


    The next level up from a UserControl is a Server Control such as this tutorial:

    The downside is that you dont get the canvas and you have to take responsibility for registering each control used within the control via code. The upside is you get full control over everything, including being able to create a great design time experience.

  • Re: Custom User Controls - Abstraction..?

    07-31-2009, 11:17 AM
    • Member
      286 point Member
    • DD85
    • Member since 07-15-2009, 10:27 AM
    • Posts 105

    Implementing properties doesn't seem like a bad way to go... It certainly works for specify images. I'm yet to play with a dynamic number of buttons. I can see how it'd work though... Hmm, I'll give it a try.

    I'll take a look into user controls, custom web controls and composite controls properly and see what I come accross. Thanks.

    Dim MyAnswer As Answer = New Answer()
    Dim CorrectAnswer As Answer = New Answer()
    If MyAnswer = CorrectAnswer Then
    MarkAsAnswer(MyAnswer)
    Thank(Me)
    End If
Page 1 of 1 (3 items)
Microsoft Communities