FiveTools
FiveTools

Reputation: 6030

Display meta tag content as a string on webpage

I have the following code:

lblMetaTag.Text = 
   "<meta property='" + ctrl.property_name + 
       "' content='" + ctrl.property_value + "' />";

When it renders to the page - it renders the meta tag and not the string representation.

How do I display it as the string?

Upvotes: 0

Views: 183

Answers (3)

NakedBrunch
NakedBrunch

Reputation: 49413

Change it to the following:

lblMetaTag.Text = 
   "&lt ;meta property='" + ctrl.property_name + "' content='" + 
    ctrl.property_value + "' /&gt ;";

Upvotes: 2

Ash Burlaczenko
Ash Burlaczenko

Reputation: 25465

This this

lblMetaTag.Text = Server.HtmlEncode(
        "<meta property='" + ctrl.property_name + 
        "' content='" + ctrl.property_value + "' />");

Hope this helps.

Upvotes: 0

Mr47
Mr47

Reputation: 2655

Use HTML encoding before sending putting it on your page.

Upvotes: 0

Related Questions