Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3357572
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:38:55+00:00 2026-05-18T02:38:55+00:00

I have implemented master pages using this example How to implement a status bar

  • 0

I have implemented master pages using this example How to implement a status bar in an ASP.NET application?. I have a property on my SiteMaster.cs inherited MasterPage called Environment. On my MasterPage.master I have this code:

<body>
    <form id="frmMaster" runat="server">
        <.. some content removed for brevity ...>

        Environment: <%= this.Environment %>
    </form>
</body>

What I would like to do is evaluate this.Environment and if it is “LIVE” then colour the background of this.Environment text red, and if it’s “TEST” colour it yellow. How would I do this?

UPDATE I’ve just added this code to MasterPage.master

protected void Page_Load(object sender, EventArgs e)
{
    lblEnvironment.Text = this.Environment;
    if (this.Environment == "LIVE")
    {
        lblEnvironment.BackColor = System.Drawing.Color.Red;
    }                
}

The page loads, but the text does not get set, it’s blank! Also the old text, that was populated is now blank too (I left the old code there for now). I also get a warning in Visual Studio:

‘ASP.masterpage_master.Page_Load(object,
System.EventArgs)’ hides inherited
member ‘SiteMaster.Page_Load(object,
System.EventArgs)’. Use the new
keyword if hiding was intended.

UPDATE2: This is what I have in SiteMaster.cs

using System;
using System.Web.UI;

public class SiteMaster : MasterPage
{
    public string StatusText { get; set; }
    public string StatusTime { get; set; }
    public string Environment { get; set; }

    protected virtual void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            if (Session["status"] != null)
            {
                this.StatusText = Session["status"].ToString();
                this.StatusTime = Session["statusTime"].ToString();
            }

            this.Environment = Session["environment"].ToString();
        }

    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T02:38:56+00:00Added an answer on May 18, 2026 at 2:38 am

    Instead of using the <%= syntax to print out the environment (this is using Response.Write), consider using a server control like a Literal or a Label. As you want to change the background colour, this suggests styling (CSS), so a Label would be appropriate.

    (A Literal is just a text placeholder and renders no HTML, whereas a Label (usually) renders the text inside <span> tags.)

    So I would change your master page markup to

    Environment: <asp:Label ID="environmentLabel" runat="server" />
    

    In the code-behind, set the Text property of environmentLabel to this.Environment. At the same time, test the value of the evironment, and set the BackColor property of the label as appropriate (or apply a CSS class).

    UPDATE:
    For a master page, you just need one class, which will inherit from System.Web.UI.MasterPage. If you create this in Visual Studio and call it SiteMaster, you’ll get 3 files:

    SiteMaster.Master (the markup)
    SiteMaster.Master.cs (the code-behind)
    SiteMaster.Master.designer.cs (automatically generated/updated)

    In the SiteMaster.Master file, you’ll want something like this:

    <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="SiteMaster.master.cs" Inherits="WebApplication1.SiteMaster" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <asp:ContentPlaceHolder ID="head" runat="server">
        </asp:ContentPlaceHolder>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:Label ID="environmentLabel" runat="server" />
    
            <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server" />
        </div>
        </form>
    </body>
    </html>
    

    In SiteMaster.Master.cs, you’ll need something like this:

    using System;
    
    namespace WebApplication1
    {
        public partial class SiteMaster : System.Web.UI.MasterPage
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                this.environmentLabel.Text = "environment";
                this.environmentLabel.BackColor = System.Drawing.Color.Red;
            }
        }
    }
    

    As the environment label is on the master page, any normal page (ASPX) using this master page will get the label displayed. Every time a page is loaded, the Page_Load event in SiteMaster.Master.cs will be called, and the text will be updated. You don’t need to define the MasterPage class yourself, that’s provided by the .NET framework.

    You may want to improve this Page_Load method, either by using ViewState and therefore only setting the text if you’re not doing a PostBack, or by disabling ViewState on the environmentLabel control.

    Finally, you’ll have one or more ASPX pages in your site, with something like this at the top of the markup:

    <%@ Page Title="" Language="C#" MasterPageFile="~/SiteMaster.Master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on migrating the ASP.NET apllication to MVC Framework. I have implemented
Hello Freinds I am new to this Asp.net MVC Control.. I have a page
I need to implement jquery blockUI for my application.. I have this code.. $.blockUI({
I have implemented tracing based on System.Diagnostics. I am also using a System.Diagnostics.TextWriterTraceListener, and
We have implemented a popup window as a modal dialog using the IE method:
I want to build a webapplication with a Single Page Interface, using ASP.NET MVC.
I have successfully implemented printing and print preview for my app using the PrintDocument,
I have found this example on StackOverflow: var people = new List<Person> { new
I have implemented what I thought was a pretty decent representation of MVC in
I have implemented a simple file upload-download mechanism. When a user clicks a file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.