A theme or a skin file is not applied to an ASP.NET control descendant
- 3 minutes to read
Description
According to ASP.NET theming concepts, the tag name in a skin file should equal to the control class name. Once you create control class descendant, the existing skin file is no longer applied.
Since DevExpress ASP.NET controls use the standard ASP.NET theming approach (skin files) internally, the above-mentioned issue with descendants also affect these controls.
You can use the following approaches to resolve this issue.
Solution 1: Use a web user control instead of a control descendant
- Create a new
WebUserControl
with a DevExpress ASP.NET control inside. - Specify the default settings for this control.
- Expose control settings as public
WebUserControl
properties and manipulate them outside theWebUserControl
.
Solution 2: Use a factory method or helper to create controls at runtime
Implement a factory method instead of a control descendant. In this case, theming is applied without extra steps because the control’s class name is not changed.
public ASPxGridView GetASPxGridViewWithDefaultSettings(string ID) {
ASPxGridView grid = new ASPxGridView();
grid.ID = ID;
grid.ClientInstanceName = ID;
//...
return grid;
}
Solution 3: Customize the applied theme
- Use the ASP.NET Theme Deployer tool to extract skin files (select the Only skin files option).
- Clone a skin file of the control whose descendant was created inside the extracted theme folder.
- Rename the cloned skin file and its tag name according to the name of the descendant class.
- Deploy the \App_Theme\Extracted_Theme folder to your web application.
- Apply the deployed theme. For more information, see the following topic: Apply a Theme with the ASP.NET Mechanism.
Example
using System;
using System.Web.UI.WebControls;
namespace CustomControls {
public class MyButtonHasOwnSkin : Button { ... }
}
<%@ Register TagPrefix="cc" Namespace="CustomControls" %>
<cc:MyButtonHasOwnSkin runat="server" BackColor="Purple" />
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Theme="RedTheme" %>
<%@ Register TagPrefix="cc" Namespace="CustomControls" %>
@* ... *@
<asp:Button ID="Button1" runat="server" Text="Default ASP.NET Button" />
<cc:MyButtonHasOwnSkin ID="Button3" runat="server" Text="Custom ASP.NET Button Has Own Skin" />
Solution 4: Create a custom theme assembly
- Use the ASP.NET Theme Builder tool to create and save a new theme based on an existing theme.
- In the saved theme sources, locate the skin file of the control whose descendant you created.
- Clone the skin file inside the extracted theme folder.
- Rename the cloned skin file and its tag name according to the name of the descendant class.
- Build a custom theme assembly from the modified theme.
- Apply the built theme. For more information, see the following topic: Apply a Theme with the DevExpress Mechanism.