Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Named Skin in ASP.NET

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.14k
    Comment on it

    What is Skin->

                            Skin was introduced in ASP.NET 2.0 to solve the problem of design/layout of server control. Its used for changing the appearance of controls like Label, CheckBox, GridView, TextBox, or Calendar Control. Skin control settings are like the control markup itself, but it contain only the properties that we want to set.

    For example, the following is a control skin for a Label control:

    <asp:Label runat="server" BackColor="red" ForeColor="black" />

    A skin file can contain control skin setting for more than one control type or we can define skin in seprate files for each control.
    We can add skin file in project by Add-> New Item-> Skin file. Here in fig we have added 2 skin files Default and White

    alt text

    When we add skin file in our project a new folder App_Theme wil be created in which this skin file would be added. There are two types of skins

    1-Default Skin
    2-Named Skin

    1-Default Skin:-
       A control skin without the skinID is the default skin. Above control skin is default skin, because it does not contain the skinID. By default it will be applicable to all the Label controls on page. It will change the layout of all Labels on page.

    2-Named Skin:-
       A control skin with SkinID property is called named skin.

    <asp:Button runat="server" BackColor="red" ForeColor="black" SkinID="RedButtonSkin" />

    Named skins do not automatically apply to controls by type. we have to explicitly apply a named skin to a control by setting the control's SkinID property. Creating named skin enables us to set different skins for different instances of the same control in an application.

    Referencing named skins:-
       We can apply named skin to control by setting the SkinID property of control. We can use above named skin for Botton control by setting the SkinID property.

    <asp:Button runat="server" id="btnButton" SkinID="RedButtonSkin"/>

    How to Apply Theme:-
     1) At Page Level:-
        We can apply the theme at page level by setting the Theme property in Page directive.

    <%@Page Theme="RedTheme" Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>

      2) At Run Time:-
         We can apply theme at runtime in Page_PreInit event handler. Because theme should be applied before initialization of controls.

    void PagePreInit(object sender, EventArgs e)
        Page.Theme = "RedTheme";

     3) At Application Level :-
         Themes can be applied at application level in web.config file. This theme would be applied on the pages in application.

            <pages theme="RedTheme"/>

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: