Skip to content

Instantly share code, notes, and snippets.

@Jerph
Created December 3, 2012 15:22
Show Gist options
  • Save Jerph/4195688 to your computer and use it in GitHub Desktop.
Save Jerph/4195688 to your computer and use it in GitHub Desktop.
ASP.NET Generic HTML5 Tag control for IE7 support
using System.Web.UI;
using System.Web.UI.WebControls;
public class Html5Tag : PlaceHolder
{
public string TagName { get; set; }
public string FallbackTagName { get; set; }
public string CssClass { get; set; }
public Html5Tag()
{
TagName = "div";
FallbackTagName = "div";
}
protected override void Render(HtmlTextWriter output)
{
string classAndID = (string.IsNullOrWhiteSpace(CssClass) ? "" : " class=\"" + CssClass + "\"")
+ (string.IsNullOrEmpty(ClientID) ? "" : " id=\"" + ClientID + "\"");
output.WriteLine("<!--[if lte IE 8 ]><" + FallbackTagName + classAndID + "><![endif]-->");
output.WriteLine("<!--[if (gt IE 8)|!(IE)]><!--><" + TagName + classAndID + "><!--<![endif]-->");
base.Render(output);
output.WriteLine("<!--[if lte IE 8 ]></" + FallbackTagName + "><![endif]-->");
output.WriteLine("<!--[if (gt IE 8)|!(IE)]><!--></" + TagName + "><!--<![endif]-->");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment