Asp.net How to display HTML contents

Asp.net How to display HTML contents

Asp.net Html Encode. 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.

Tags:

html without using tables tableless html table less html css tableless layoutsBasic HTML5 TagsAsp.net Create Html ControlsC# HtmlTextWriter ExampleASP.net HTML5 Generate Article TagThis page contains secure and none secure information Do you want to display the none secure itemsDo you want to display nonsecure itemsAsp.net access html control textbox element value at code behindRegularExpression remove html tagsOnline html editor online JavaScript editorasp net image uploadASP.net File Handling

Author

My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in ASP.net year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.
 

I'm Satalaj.