|
|||||||||||||||||||||
|
|||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionThemes in ASP.NET 2.0 is another cool new feature added to the plethora of additions and improvements made into the next version of the programming model. Using themes, you can easily customize your server controls with the pre-defined looks bundled with the .NET Framework or can make your own themes according to the look and feel of your website. Designing a website was never this easy before. What are themesThemes are introduced in ASP.NET 2.0 to counter the troubles faced by developers to define the layout of server controls and make them look coherent to the overall application, with minimum possible efforts. Default or Global themes are contained in a special folder inside the framework and can be declared in the source as well as class files. However, custom made themes can also be saved inside the predefined "App_Themes" folder inside ASP.NET applications, making them easier to manage and interpolate according to your needs. The essential part of themes are skin files with .skin extension. Besides skin files, a theme can be composed of styles sheets .css files as well as images for added support for the layout of the website. Global themesBuilt-in themes are saved in a special location under the installation path of the .NET Framework 2.0: [Editor coment: Line breaks used to avoid scrolling.] %SystemRoot%\Microsoft.NET\Framework\VX.X.XXXX\
ASP.NETClientFiles\Themes\
The actual name of the subdirectory labeled vX.X.XXXX changes according to the build of ASP.NET 2.0 that you're considering. Themes defined in this path are visible to all applications running on the machine. However, ASP.NET 2.0 Beta 2 users will not find this folder in the specified location because ASP.NET team has dropped the Global Themes support from the beta 2 release of the product. But they will provide pre-defined themes as an add-on when Microsoft launches Visual Studio 2005 in November this year. These add-on themes can be purchased or downloaded separately and will be installed in the specified folder above. How to apply themesThemes can be used by a variety of methods. The following examples show you how you can define a theme named " <%@ Page Theme="SmokeAndGlass" Language="C#"%>
Themes can be set programmatically under the protected void Page_PreInit(object sender, EventArgs e)
{
// Applying theme to a particular page
Page.Theme = "SmokeAndGlass";
}
Themes can also be stored in the web.config file which will be applied to the overall application. Themes declared in this file are therefore not required to be declared in any other file under the <configuration>
<system.web>
<pages theme=“SmokeAndGlass” />
</system.web>
</configuration>
Creating themesYou can create your own themes for applying to your site or individual pages. A page theme is defined in a special App_Themes folder under the root of a web application. In the page theme you define control skins - settings for individual controls such as <asp:Label runat="server" ForeColor="#585880"
Font-Size="0.9em" Font-Names="Verdana" />
<asp:Calendar runat="server" BorderStyle="double"
BorderColor="#E7E5DB" BorderWidth="2" BackColor="#F8F7F4"
Font-Size=".9em" Font-Names="Verdana">
<TodayDayStyle BackColor="#F8F7F4" BorderWidth="1"
BorderColor="#585880" ForeColor="#585880" />
<OtherMonthDayStyle BackColor="transparent"
ForeColor="#CCCCCC" />
<SelectedDayStyle ForeColor="#6464FE"
BackColor="transparent"
cssclass="theme_highlighted" />
<TitleStyle Font-Bold="True" BackColor="#CCCCCC"
ForeColor="#585880" BorderColor="#CCCCCC"
BorderWidth="1pt" cssclass="theme_header" />
<NextPrevStyle Font-Bold="True" ForeColor="#585880"
BorderColor="transparent"
BackColor="transparent" />
<DayStyle ForeColor="#000000" BorderColor="transparent"
BackColor="transparent" />
<SelectorStyle Font-Bold="True" ForeColor="#696969"
BackColor="#F8F7F4" />
<WeekendDayStyle Font-Bold="False"
ForeColor="#000000" BackColor="transparent" />
<DayHeaderStyle Font-Bold="True" ForeColor="#585880"
BackColor="Transparent" />
</asp:Calendar>
All global themes that were released with Beta 1 can be found inside the .zip sample application. These files can help you understand the skin files better. Named skinsSkins without Named skins<asp:Label runat="server" ForeColor="#585880"
Font-Size="0.9em" Font-Names="Verdana" SkinID="LabelHeader" />
<asp:Label runat="server" ForeColor="#585980" Font-Size="0.8em"
Font-Names="Arial" SkinID="LabelFooter" />
Referencing named skins<asp:Label id="Header" runat="server" SkinID="LabelHeader" />
<asp:Label id="Header" runat="server" SkinID="LabelFooter" />
Dynamically applying themesThemes can be dynamically applied to your application by adding a few lines of code. This will give users an option to select themes according to their taste. Here is an example showing you how to achieve this functionality: protected void Page_PreInit(object sender, EventArgs e)
{
string theme = ""; // setting the value to none
if (Page.Request.Form.Count > 0)
{
// "Themes" is the ID of dropdownlist
theme = Page.Request["Themes"].ToString();
if (theme == "Default")
{
theme = "";
}
}
this.Theme = theme; // applying themes to the overall page
}
All the controls defined in your Web Forms inherit the properties defined in the theme you select from the DropDownList with ID="Themes". You have to add all the global as well as custom made themes under the "App_Themes" folder in your application, the above mentioned example will not access themes inside the global themes folder.
ConclusionASP.NET 2.0 themes are somewhat identical to the Windows XP and Windows Server 2003 themes and provide skins for a variety of controls. Themes are the next big thing in styling after CSS style sheets. Themes can be manipulated programmatically unlike style sheets. All in all, ASP.NET 2.0 themes and skin files are a huge leap forward in providing the best styling experience for web developers in the shortest possible time.
| ||||||||||||||||||||