Asp.net How to display HTML contents
Do you want to show HTML source content on page? It's simple with HttpUtility.HtmlEncode method. Here we will see both C#.net and VB.net examples of encoding HTML content for display.
Asp.net Html Encode.
Let's see Asp.net C# HTML encode example.
protected void Page_Load(object sender, EventArgs e)
{
string htmlContent = "<b>This is bold string.</b><I>This is itallic string.</I>";
string htmlOutput = HttpUtility.HtmlEncode(htmlContent);
Response.Write("Html Content are: "+ htmlContent);
Response.Write("</br>");
Response.Write("Html Source Content are: " + htmlOutput);
}
VB.net Html Encode.
Protected Sub Page_Load(sender As Object, e As EventArgs)
Dim htmlContent As String = "<b>This is bold string.</b><I>This is itallic string.</I>"
Dim htmlOutput As String = HttpUtility.HtmlEncode(htmlContent)
Response.Write("Html Content are: " + htmlContent)
Response.Write("</br>")
Response.Write("Html Source Content are: " + htmlOutput)
End Sub
This is very simple way of rendering the HTML content over browser. If html content are not encoded, browser display it as HTML.
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5