Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 3 - Using Themes and Skins for Personalization...
Iron Speed
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC.NET

Using Themes and Skins for Personalization with Visual Basic 2005
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 14
    2006-12-07

    Table of Contents:
  • Using Themes and Skins for Personalization with Visual Basic 2005
  • Organize Site Themes and Skins
  • Enable Themes and Skins
  • Using Named Skins
  • Web Parts
  • Enabling Editing and Layout Changes
  • Editing a Part

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    Iron Speed
     
    ADVERTISEMENT

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Using Themes and Skins for Personalization with Visual Basic 2005 - Enable Themes and Skins
    (Page 3 of 7 )

    To let your users choose the theme they like and have their preference stored in their profile, you need to add a single line to the properties element in the profile element of Web.config:

      <add name="Theme" />

    Save and rebuild your application.

    Specify Themes for Your Page

    You can set the themes on your page either declaratively or programmatically. To set a theme declaratively, add the Theme attribute to the Page directive:

      <%@ Page Language="VB" AutoEventWireup="true"
      CodeFile="Default.aspx.vb" Inherits="Default_aspx" Theme="Dark Blue"%>

    You can also set the theme programmatically, either by hard coding it or (even better) by setting it from the user’s profile.

    StyleSheet themes are set by overriding theStyleSheetThemeproperty for the page. IntelliSense will help you with this. Open Welcome.aspx.vb and scroll to the bottom of the class. Type the word overrides and all the overridable members are shown. Start typing sty and IntelliSense will scroll to the property you want:StyleSheetTheme, as shown in Figure 12-48.


    Figure 12-48.  Overriding a method

    Once IntelliSense finds the property you want, press Tab to accept it. Fill in the accessors, as shown in Example 12-22.

    Example 12-22. Setting a StylesheetTheme property

    Public Overrides Property StyleSheetTheme() As String
        Get
           If Profile.IsAnonymous = False And Profile.Theme IsNot Nothing Then
               Return Profile.Theme
           Else
               Return "Dark Blue"
          
    End If
        End Get
        Set(ByVal value As String)
           Profile.Theme = value
        End Set
    End Property

    If you are going to set a customization theme programmatically, however, you must do so from thePreInitevent handler for the page,* because the theme must be set before the controls are created. APreInitevent handler is shown in Example 12-23.

    Example 12-23. Welcome page PreInit event handler

    Protected Sub Page_PreInit( _
    ByVal sender As Object, ByVal e As System.EventArgs) _
    Handles Me.PreInit
       
    If Profile.IsAnonymous = False Then
           
    Page.Theme = Profile.Theme
        End If
    End Sub

    Setting the theme inPreInitcreates a bit of a difficulty when you want to allow the user to change the theme at runtime. If you create a control that posts the page back with a new theme, thePreInit code runs before the event handler for the button that changes the theme, and so by the time the theme is changed, the controls have already been drawn.

    * The pre-init event is new in Visual Basic 2005.

    To overcome this you must, unfortunately, refresh the page again. An alternative is to set the themes in another page. For example, add two buttons to the ProfileInfo.aspx page (at the bottom of the table at the bottom of the page). Set the properties of the first button to:

      ID="ThemeBlue" Text="Dark Blue" OnClick="Set_Theme"

    Set the properties of the second button to:

    ID="ThemePsychedelic" Text="Psychedelic" OnClick="Set_Theme"

    Notice that the two buttons share a single Click event handler,Set_Theme, shown in Example 12-24. An easy way to have Visual Studio 2005 set up that event handler for you is to switch to Design view and click on one of the buttons. Click on the lightning bolt in the Properties window to go to the events, and double-click on theSet_Themeevent. You are now ready to implement the event handler. You’ll cast the sender to the button and check its text, setting the theme appropriately.

    Example 12-24. Common Click event handler for ThemeBlue and ThemePsychedelic buttons

    Protected Sub Set_Theme( _
    ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles ThemePsych.Click
        Dim btn As Button = CType(sender, Button)
        If btn.Text = "Psychedelic" Then
            Profile.Theme = "Psychedelic"
        Else
            Profile.Theme = "Dark Blue" 
        End If
    End Sub

    When the user is not logged on, the Welcome page’s default theme will be used. Once the user sets a theme in the profile, that theme will be used when you return to the Welcome page. Create skins for your two themes and then run the application to see the effect of applying the themes.

    More Visual Basic.NET Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "Programming Visual Basic 2005," published...
     

    Buy this book now. This article is excerpted from chapter 12 of the book Programming Visual Basic 2005, written by Jesse Liberty (O'Reilly, 2005; ISBN: 0596009496). Check it out today at your favorite bookstore. Buy this book now.

    VISUAL BASIC.NET ARTICLES

    - Types of Operators in Visual Basic
    - Operators
    - Understanding Custom Events using Visual Bas...
    - Polymorphism using Abstract Classes in Visua...
    - Shadowing using Shadows in Visual Basic.NET ...
    - Overloading and Overriding in Visual Basic.N...
    - More on Controlling Windows Fax Services Usi...
    - Programmatically Controlling Windows Fax Ser...
    - Focusing on Forms and Menus in Visual Basic
    - Manipulating Forms with the Windows Forms Li...
    - Basics of the Windows Forms Library
    - Forms, Controls, and Other Useful Objects
    - Implementing OOP to Develop Database Oriente...
    - Using Themes and Skins for Personalization w...
    - A Deeper Look at Personalization using Visua...

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway