Setting Default Values on Your Custom Control

Today when I was working with creation of server controls, I realized that I wanted my server controls to work out of the box using default values when you drag and drop the control onto the designer surface. That's when I started digging into what do I needed to do on my server controls to set default values. Sure enough I welcomed the new attribute ToolBoxData in which you can specify default values for the properties of your control when it gets dragged. Here is an example of Address server control in which I am setting default values for the properties address,city, state and zip on my address control.

image

In the above example I am making use of ToolBoxData attribute at the class level and setting default values for the properties of my control. Once I set these properties and drag the control this is what visual studio puts on the designer.

image

No Comments