Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>On the master page add the following controls: the hfMsg hidden field will hold the message that will be displayed and the hfCtrl will hold the name of the html control that will display this message which will be in this example lblMsg.</p> <pre><code>&lt;label id="lblMsg" style="background-color:Yellow; border:solid 1px; width:200px;height:100px;display:none;"&gt;&lt;/label&gt; &lt;asp:HiddenField ID="hfMsg" runat="server" /&gt; &lt;asp:HiddenField ID="hfCtrl" runat="server" /&gt; </code></pre> <p>NOTE:you can add another html control with a different id on an ASCX control and use it to display the message instead of the lblMsg.</p> <p>and the following script:</p> <pre><code>&lt;script language="javascript" type="text/javascript"&gt; var msg = $('#&lt;%= hfMsg.ClientID %&gt;').attr("value"); var ctrl = $('#&lt;%= hfCtrl.ClientID %&gt;').attr("value"); if (msg != undefined &amp;&amp; msg != "") { $("#" + ctrl).html(msg); $("#" + ctrl).show(); } else { $("#" + ctrl).hide(); } &lt;/script&gt; </code></pre> <p>NOTE:the script simply checks to see if the hfMsg control has a message to display or not.</p> <p>and add the following two methods to the master page:</p> <pre><code>public void ShowMessage(string control, string message) { this.hfCtrl.Value = control; this.hfMsg.Value = message; } public void ClearMessage() { this.hfMsg.Value = string.Empty; } </code></pre> <p>finally you can call the ShowMessage method from any page like this to display a message on the master page:</p> <pre><code>Master.ShowMessage("lblMsg","hello world!"); </code></pre> <p>and if you have a user control that holds an html label (e.g lblUserMsg) to display the message you can simply call ShowMessage and pass it the name of the label:</p> <pre><code>Master.ShowMessage("lblUserMsg","hello world!"); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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