Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to implement a status bar in an ASP.NET application?
    text
    copied!<p>I have a simple ASP.NET application which has one master page called MasterPage.master. In MasterPage.master I have a Label called <code>lblStatus</code>. I want to update the text of this label when certain events happen in the website and always display the latest status no matter which web page I am on in the site.</p> <p>This is what I'm thinking of doing, but I'm unsure if this is the most elegant:</p> <ol> <li>Create a new class file with the code to update session state <code>Session["status"]</code></li> <li>Call a method in this new class file to update Session state whenever something happens</li> <li>In the PageLoad event of the MasterPage.master page, update the <code>lblStatus.Text</code> with <code>Session["status"]</code></li> </ol> <p>Questions</p> <ol> <li>Should I use a <code>Literal</code> instead of a <code>Label</code>? </li> <li>Would it be better to do it another way?</li> </ol> <p>Thanks, here's my code so far in MasterPage.master:</p> <pre><code>&lt;%@ Master Language="C#" %&gt; &lt;script runat="server"&gt; public string StatusText { get { return ltlStatus.Text; } set { ltlStatus.Text = value; } } &lt;/script&gt; &lt;html&gt; &lt;head runat="server" id="Header"&gt; &lt;asp:contentplaceholder id="ContentPlaceHolderScript" runat="server" /&gt; &lt;title&gt;MooDB - &lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="frmMaster" runat="server"&gt; &lt;div&gt; &lt;asp:Menu ID="mnuNav" Orientation="Horizontal" runat="server"&gt; &lt;.. removed for brevity ..&gt; &lt;/asp:Menu&gt; &lt;/div&gt; &lt;div&gt; &lt;asp:Literal ID="ltlStatus" runat="server" /&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>I'm unsure of the next bit. Do I need to copy this code onto every page in my site:? </p> <pre><code>&lt;%@ Page Language="C#" %&gt; &lt;script runat="server"&gt; private void ChangeStatus(string newStatus) { ((SiteMaster)this.Master).StatusText = newStatus; } &lt;/script&gt; &lt;asp:Content ContentPlaceHolderID="contentMain" runat="server" ID="Main" &gt; &lt;... my page content ...&gt; &lt;/asp:Content&gt; </code></pre> <p>Sorry I'm new to ASP.NET and I'm not sure what to do. What is SiteMaster?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload