•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Web Development category of DaniWeb, a massive community of 374,047 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,924 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Web Development advertiser:
Sep 9th, 2006, 5:08 am
ASP.net 2.0 introduced themes. Theme consists of several files: CSS styles, skin file and images. You create theme by adding App_Themes folder in your project in solution explorer panel.
Right click on project - Add ASP.net folder - Theme
Now that we created theme we can add files into it. The best practice is to add only one CSS file to lower bandwidth usage.
When you add asp.net control in asp.net page or user control you can set up SkinId property of the control. Here is the example of how to customize logo for themes:
aspx page:
[HTML]
<asp:Image ID="imgLogo" runat="server" SkinID="Logo" />
[/HTML]
Now we need to create new skin file. Right click on Theme folder and choose Add New Item - Skin File.
In skin file you can add elements and give them properties like:
skin file:
[HTML]
<asp:Image SkinId="Logo" runat="server" ImageUrl="Logo.jpg" Tooltip="Our company logo" AlternateText="Logo" />
[/HTML]
Now you need to create Logo.jpg file and put in in Theme folder.
To apply default theme put StylesheetTheme and Theme properties in Page declaration of the aspx page like:
[HTML]
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default"
StylesheetTheme="Standard" Theme="Standard" %>
[/HTML]
Test it and see that theme is applied to page.
How to set up theme runtime?
There are many ways to set up theme depending on user choise. I have set up page where user can choose theme from dropdownlist. First I have added default theme in Global.asax file, like:
In aspx page I have one dropdownlist which is filled with Theme names. Here is the sub to fill dropdownlist with theme names:
When you choose theme from list you need to click button "Save settings" to set theme:
For all this to work you need to add this code in PreInit event of the page you are setting theme for.
To see how all this works go to http://www.akcija.ba and click on link "Postavke", there choose a theme (Standard or Ocean) and click button "Spremi". IF you want your setting permanently saved check "Trajno spremi moje postavke" option.
Right click on project - Add ASP.net folder - Theme
Now that we created theme we can add files into it. The best practice is to add only one CSS file to lower bandwidth usage.
When you add asp.net control in asp.net page or user control you can set up SkinId property of the control. Here is the example of how to customize logo for themes:
aspx page:
[HTML]
<asp:Image ID="imgLogo" runat="server" SkinID="Logo" />
[/HTML]
Now we need to create new skin file. Right click on Theme folder and choose Add New Item - Skin File.
In skin file you can add elements and give them properties like:
skin file:
[HTML]
<asp:Image SkinId="Logo" runat="server" ImageUrl="Logo.jpg" Tooltip="Our company logo" AlternateText="Logo" />
[/HTML]
Now you need to create Logo.jpg file and put in in Theme folder.
To apply default theme put StylesheetTheme and Theme properties in Page declaration of the aspx page like:
[HTML]
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default"
StylesheetTheme="Standard" Theme="Standard" %>
[/HTML]
Test it and see that theme is applied to page.
How to set up theme runtime?
There are many ways to set up theme depending on user choise. I have set up page where user can choose theme from dropdownlist. First I have added default theme in Global.asax file, like:
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
Session("Theme") = "Standard"
End SubIn aspx page I have one dropdownlist which is filled with Theme names. Here is the sub to fill dropdownlist with theme names:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Page.IsPostBack = False Then
Dim dirs As String() = IO.Directory.GetDirectories(Server.MapPath("~/App_Themes/"))
For Each dir As String In dirs
Me.cmbTheme.Items.Add(dir.Substring(dir.LastIndexOf("\") + 1))
Next
'set current settings
Me.cmbTheme.SelectedValue = Me.Page.Theme
End If
End SubWhen you choose theme from list you need to click button "Save settings" to set theme:
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
Session("Theme") = Me.cmbTheme.SelectedValue
End SubFor all this to work you need to add this code in PreInit event of the page you are setting theme for.
Me.Page.Theme = Session("Theme")To see how all this works go to http://www.akcija.ba and click on link "Postavke", there choose a theme (Standard or Ocean) and click button "Spremi". IF you want your setting permanently saved check "Trajno spremi moje postavke" option.
This blog entry was written by ManicCW. It has received 5,573 views, 0 comments, and 8 linkbacks. 1 voter has rated this entry 5 out of 5 stars.
•
•
•
•
.net ajax app portability asp custom developer development dom feed firefox ie java linux microsoft mobile msdn news office reader safari skin software sql theme virtualization vista weather windows xml xoap
All Recent Tags Post Comment
•
•
•
•
Only community members can start a blog or comment on blog entries. You must register or log in to contribute.
•
•
•
•
•
•
•
•
DaniWeb Web Development Marketplace
Related Blog Entries
- Open Web Foundation to Help Shepard Standards (7 Hours Ago)
- DNS Security Flaw In the Wrong Hands? (2 Days Ago)
- ISO Uses PDFs Too, Standardizes Format (22 Days Ago)
- Microsoft announces host of new Internet Explorer 8 security features (22 Days Ago)
- Latest Mac OS X Trojan Might Be Sign of Things to Come (24 Days Ago)
- Yahoo Mail Open—then Closed—to Hackers (28 Days Ago)
- Barack Obama is following me on Twitter! (29 Days Ago)
- Salesforce Says ‘Hey, Google, Get Onto My Cloud’ (31 Days Ago)
- Web forms are still the gateway to security hell (33 Days Ago)
- Ruby, Ruby, Ruby - Vulnerable, Vulnerable, Vulnerable (33 Days Ago)
Related Forum Threads