Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Why not a simple HTML "old-school" extension method? (i.e static method)</p> <pre><code>namespace Web.Helpers { public class HtmlHelpers { public static string Label(string target) { var dynamicText = SomeWhere.GetSomeCoolText(); return String.Format("&lt;label for='{0}'&gt;{1}&lt;/label&gt;", target, dynamicText); } } } </code></pre> <p>Then in your HTML:</p> <pre><code>&lt;%= HtmlHelpers.Label("sometarget") =&gt; </code></pre> <p>In your main master page, just import the namespace:</p> <pre><code>&lt;%@ Import Namespace="Web.Helpers" %&gt; </code></pre> <p><strong>EDIT after question updated</strong></p> <p>Ok, i see what you're trying to do now. I would recommend doing it all client-side. </p> <p>That is, in your main master page, create an initially hidden <code>&lt;div&gt;</code> with a unique id:</p> <pre><code>&lt;div id="message" style="display: none"&gt;&lt;/div&gt; </code></pre> <p>Then create a helper method somewhere in your web project, rendering out some script.</p> <pre><code>public void DisplayMessage() { string message = SomeWhere.GetSomeCoolText(); StringBuilder script = new StringBuilder(); script.AppendFormat("$('message').show().append("&lt;span&gt;{0}&lt;/span&gt;")", message); Page.ClientScript.RegisterClientScriptBlock(this.GetType(), script.ToString(), true); } </code></pre> <p>Of course, this is just a guideline. You dont have to use jQuery, you don't have to hardcode the script in the method. You could create a JavaScript function that accepts a string and modifies the HTML of the div, then just call the function.</p> <p>It all depends on how complicated your "message" is, if you need special server controls, internationalization, etc.</p> <p>But this is certainly the easiest way to accomplish what you want (IMHO).</p>
    singulars
    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