Wednesday, 10 July 2013

Switch Body or another HTML Tag css class using master page and runat="server"

If you want to change the class on a body or html tag then you can target the master page and run a check. This following example is done using umbraco and allows you to check the node you are on then adde the class to that page accordingly. On your ASPX page you will need to mark up you body tag with: on your ASP.CS file you will require something along the lines of: using umbraco.NodeFactory; public partial class Core : System.Web.UI.MasterPage { public void Page_Load(object sender, EventArgs e) { HtmlGenericControl MasterPageBodyTag = (HtmlGenericControl)Master.FindControl("MasterPageBodyTag"); if (Node.GetCurrent() == 1111) { MasterPageBodyTag.Attributes.Add("class", "your-class"); } } So when the node is 1111 it will add the additional class. This has various uses, but it mainly used for when marking up for design purposes.

No comments: