How to Use RadControls for ASP.NET AJAX Embedded Skins with a HTML DOCTYPE

Thread is closed for posting
1 posts, 1 answers
  1. Answer
    Telerik Admin
    Telerik Admin avatar
    1679 posts
    Member since:
    Oct 2004

    Posted 21 Aug 2008 Link to this post


    RadControls version RadControls for ASP.NET AJAX
    .NET version 2.0
    Visual Studio version
    programming language C#, VB
    browser support

    all browsers supported by RadControls


    By default, ASP.NET produces XHTML markup, which means that <link> tags (added programmatically as HtmlLink elements) are always self-closing. This is not valid if you are using an HTML DOCTYPE. In order to make your markup validate and still continue using automatically registered embedded skins, you need to replace the self-closing <link> tags with open tags:


    protected void Page_PreRenderComplete(object sender, EventArgs e) 
        List<HtmlLink> oldSkins = new List<HtmlLink>(); 
        List<LiteralControl> newSkins = new List<LiteralControl>(); 
        foreach (Control c in Page.Header.Controls) 
            if (c is HtmlLink && (c as HtmlLink).Attributes["class"] == "Telerik_stylesheet"
                LiteralControl lc = new LiteralControl(String.Format("<link href=\"{0}\" type=\"text/css\" rel=\"stylesheet\" class=\"Telerik_stylesheet\">", (c as HtmlLink).Href.Replace("&t""&amp;t"))); 
                oldSkins.Add(c as HtmlLink); 
        foreach (HtmlLink oldSkin in oldSkins) 
        foreach (LiteralControl newSkin in newSkins) 


        Protected Sub Page_PreRenderComplete(ByVal sender As ObjectByVal e As EventArgs) Handles Me.PreRenderComplete 
            Dim oldSkins As New List(Of HtmlLink)() 
            Dim newSkins As New List(Of LiteralControl)() 
            For Each c As Control In Me.Header.Controls 
                If TypeOf c Is HtmlLink AndAlso TryCast(c, HtmlLink).Attributes("class") = "Telerik_stylesheet" Then 
                    Dim lc As New LiteralControl([String].Format("<link href='{0}' type='text/css' rel='stylesheet' class='Telerik_stylesheet'>", (TryCast(c, HtmlLink)).Href.Replace("&t""&amp;t"))) 
                End If 
            For Each oldSkin As HtmlLink In oldSkins 
            For Each newSkin As LiteralControl In newSkins 
        End Sub 

    By the way, in order to make ASP.NET render more HTML-compliant markup, you can set in web.config:

        <xhtmlConformance mode="Legacy" /> 

    However, you should be aware that this creates problems with ASP.NET AJAX:

    Gotcha: Don't use xhtmlConformance mode="Legacy" with ASP.NET AJAX

    For more information about ASP.NET 2.0 and web standards, please visit:

    MSDN: Building ASP.NET 2.0 Web Sites Using Web Standards

Back to Top