There are very nice thing in asp.net called themes. This is a folder, located under App_Themes, inside this folder you can put images, css files and .skin files. The skin file allows you to set some asp.net controls properties theme-wide. It looks like
<asp:Button runat="server" BackColor="#ff46a1" BorderWidth="1px" BorderColor="#666666" ForeColor="#666666" BorderStyle="Solid" />
But what to do with custom controls? When you are writing custom control you need to do several things:
First thing you need to do - add line to assemblyinfo.cs,
[assembly: TagPrefix("SampleNamespace", "sample")]
to define tag prefix for your control.
Now you can use <#@ Register... inside your skin file, and write in skin file something like this:
<sample:SampleControl runat="server" BackColor="#ff46a1"
BorderWidth="1px" BorderColor="#666666" ForeColor="#666666" CustomImageProperty="images/bg.gif" BorderStyle="Solid" />
This is good, but one problem exist. Skin file allows you to setup images, and these images are relative to theme directory. But CustomImageProperty by default remains relative to page, and this is a problem. How to solve it? We need to use [UrlProperty()] attribute in our custom control. UrlPropertyAttribute shows asp.net that this property is a path, and in case of skins should be substituted. This way path will be relative to theme's folder, and we are happy.