Skip to content
Article

Dynamic Body ID and Class properties on ASP.NET Master Pages

Master pages are a great feature of ASP.NET. However, they do have some drawbacks, one being they do not easily offer the flexibility of dynamic body ids and classes that our design team here needs.

Luckily a solution exists, and best of all it isn’t all that difficult to implement. The solution is built around the idea that child pages can access their master page, as well as any publicly exposed properties on the master. For example, in the Page_Load method of a child page, you can write:

MyMasterPage masterPage = Master as MyMasterPage; masterPage.Property = “property value”;

This is not ideal though, because we are now committed to never changing our child’s master page; if we do, it will break our build. The correct implementation of this concept is to create an interface that all of our master pages will implement, then use that in our child pages’ Page_Load method:

IMasterPage masterPage = Master as IMasterPage; masterPage.Property = “property value”;

We can still set our property this way, only now we can later change what master page we use, as long as the new one still implements the same interface. Good stuff. So good, that it puts us most of the way there towards dynamic body ids and classes.

To get these, we need a couple of properties on our interface:

public interface IMasterPage { String BodyId { get; set; } String BodyClass { get; set; } }

Then, in the code-behind file for our actual master page:

public partial class MasterPagesDefault : MasterPage, IMasterPage { private string _bodyId; private string _bodyClass; public string BodyId { get { return _bodyId; } set { _bodyId = value; } } public string BodyClass { get { return _bodyClass; } set { _bodyClass = value;} } }

Finally, in the master page’s body tag:

<body id=”<%= BodyId %>” class=”<%= BodyClass %>”>

Now, to set these dynamically, use the child page’s Page_Load method just like before:

IMasterPage masterPage = Master as IMasterPage; if (masterPage != null) { masterPage.BodyId = “index”; masterPage.BodyClass = “index two-col”; }

By using publicly accessible properties, we give child pages the ability to set values on their master page. With this, it is easy to create dynamic body classes and ids in .NET.

The Atlantic BT Manifesto

The Ultimate Guide To Planning A Complex Web Project

Insights

Atlantic BT's Insights

We’re sharing the latest concepts in tech, design, and software development. Learn more about our findings.

Questions & Answers

Can you integrate with my existing systems and teams?

Yes, both technically and operationally. On the technical side, our engineering heritage allows us to connect modern cloud, data, and AI capabilities securely to your existing ERPs, CRMs, and proprietary software using SOC 2 Type 2 certified practices. On the operational side, we never work in a silo. Our senior architects embed directly with your in-house developers and stakeholders, aligning with your governance protocols and building internal capability so your team can confidently maintain and scale the system.

Learn More about Can you integrate with my existing systems and teams?
Why should we pay for a discovery phase when we can jump straight into development?

Investing in a strategy and discovery phase prevents costly rework, scope creep, and misaligned features before your engineering budget is committed to full-scale development. While jumping straight into writing code can feel faster at the beginning, uncovering hidden legacy bottlenecks, unclear user requirements, or integration roadblocks midway through a build is significantly more expensive to fix in production than on paper.

A structured discovery phase protects your budget and timeline in four practical ways:

  • Validates Assumptions Before Engineering Begins: Through stakeholder interviews, workflow observations, and a clickable prototype, your team can test user flows and gather real feedback early so we can ensure we build the exact features your business needs.
  • Uncovers Hidden Technical Constraints: Auditing your existing databases, APIs, and security requirements upfront reveals integration hurdles and technical debt before developers write a single line of production code.
  • Produces Accurate Budgets & Timelines: Defining clear technical requirements and architecture blueprints eliminates guesswork, giving leadership reliable cost estimates and realistic delivery milestones.
  • Aligns Leadership & Technical Teams: Getting executive sponsors, end users, and IT stakeholders on the same page early prevents mid-project priority shifts that stall momentum and inflate costs.

Learn More about Why should we pay for a discovery phase when we can jump straight into development?
What does my business get by the end of a technology consulting engagement?

At the end of a technology consulting engagement with Atlantic BT, your business walks away with a clear, actionable blueprint and a validated prototype so your leadership team can move into development with full confidence. Rather than leaving you with high-level theory, our senior architects deliver concrete artifacts built around your actual operations:

  • Stakeholder & Workflow Findings: Insights gathered from executive stakeholder interviews and hands-on contextual inquiries that map out how your teams currently work and where daily bottlenecks occur.
  • Comprehensive Systems Audit: A technical evaluation of your existing software stack, databases, integrations, and security posture to pinpoint technical debt and modernization opportunities.
  • Prioritized Recommendations & Roadmap: An objective, vendor-agnostic plan outlining which software, cloud, or AI solutions will deliver the highest return on investment, complete with scope, timeline, and budget estimates.
  • Fully Clickable Prototype: If building software, an interactive front-end prototype that lets your team test user flows, validate assumptions, and gather real feedback before investing in full-scale engineering.

Learn More about What does my business get by the end of a technology consulting engagement?
What does enterprise technology consulting cost for businesses?

A focused enterprise AI readiness assessment and strategy roadmap typically ranges from $10,000 to $75,000, depending on the complexity of your data infrastructure, security requirements, and the number of workflows evaluated. At Atlantic BT, we scope engagements transparently around defined deliverables, such as a systems audit, prioritized ROI roadmap, and working prototype, so you can validate business value before committing to full-scale development. 

Our initial AI strategy discovery process starts at $10,000 and includes evaluation of 3 workflows and initial suggestions.

Learn More about What does enterprise technology consulting cost for businesses?