Last post Jul 31, 2009 11:17 AM by DD85
Jul 31, 2009 07:00 AM|DD85|LINK
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.
Jul 31, 2009 08:21 AM|rtpHarry|LINK
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
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.
Jul 31, 2009 11:17 AM|DD85|LINK
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.