jason lu
jason lu

Reputation: 56

Applying a skinid to a label using themes in asp.net

I was trying to apply a skin on runtime to a label using a skinid i created from a skin file. The theme folder is called skin1. The SkinID is called Error. When I try to Apply the Skin1 theme folder thru the Page_PreInt Method to the label using the skinid, Nothing seems to happen.

Code:

protected void Page_PreInit(object sender, EventArgs e)
    {
        Session["Mytheme"] = "Skin1";
        lblMessage.SkinID = Session["Mytheme"].ToString();
    }

The Label in the Hmtl:

<asp:Label ID="lblMessage" runat="server" SkinID="Error"  Text="HELLO WORLD">
</asp:Label>

The Skin file in the theme folder:

<asp:Label runat="server" SkinID="Error" ForeColor="Red"/>

Upvotes: 0

Views: 1574

Answers (1)

codemonkeh
codemonkeh

Reputation: 2152

To skin just this one control you need to apply the theme, but turn it off at the page level and on at for the controls you wish to skin. E.g.

<%@ Page Theme="skin1" EnableTheming="false" %>

And then setting the skin id should be sufficient:

<asp:Label ID="lblMessage" runat="server" SkinID="Error" Text="HELLO WORLD" EnableTheming="true">
</asp:Label>

Or programmatically:

Page.EnableTheming = false;
Page.Theme = "skin1";
lblMessage.SkinID = "Error";
lblMessage.EnableTheming = true;

Upvotes: 1

Related Questions