Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between InnerHTML and InnerText property of ASP.Net controls?

While using ASP.NET controls, for example

<h1 id="header" runat="server">text</h1>

if we want to change the text of the header we can do it probably by two properties InnerHTML and InnerText. I want to know what is the basic difference between the two properties?

like image 651
techfun Avatar asked Oct 16 '13 20:10

techfun


1 Answers

InnerHtml lets you enter HTML code directly, InnerText formats everything you put in there for it to be taken as plain text.

For example, if you were to enter this in both properties: Hello <b>world</b>

This is what you would get with InnerHTML:

Hello world

That is, exactly the same HTML you entered.

Instead, if you use InnerText, you get this:

Hello <b>world</b>

And the resulting HTML would be Hello &lt;b&gt;world&lt;/b&gt;

like image 124
Yandros Avatar answered Oct 16 '22 23:10

Yandros