You can use the management adapter to gently inject this behavior into the page as follows:
public class PageAdapter : System.Web.UI.Adapters.PageAdapter { protected override void OnPreRender(System.EventArgs e) { foreach (var link in Page.Header.Controls.OfType<HtmlLink>().ToList()) if (link.Attributes["type"].Equals("text/css", StringComparison.OrdinalIgnoreCase)) if (link.Attributes["href"].Contains("/App_Themes/{0}/".Fill(Page.Theme), StringComparison.OrdinalIgnoreCase)) base.OnPreRender(e); } }
You can connect it by saving the following in a * file . browser in the App_Browsers folder:
<browsers> <browser refID="Default"> <controlAdapters> <adapter controlType="System.Web.UI.Page" adapterType="PageAdapter" /> </controlAdapters> </browser> </browsers>
Overall, I think Control Adapters are a powerful AOP-like mechanism for injecting behavior into control / page life cycles; they are almost completely ignored in favor of the traditional subclass.
Nariman
source share