Swag
Swag

Reputation: 2140

Disable HTML asp textbox

When I use a HTML-element in my textboxes I was getting this error:

enter image description here

To fix this error, I did this:

  1. Adding ValidateRequest="false" at the top of the .aspx page.
  2. Adding <httpRuntime targetFramework="4.0" requestValidationMode="2.0" /> to the webconfig file.

After doing this, the error above didnt appear, and the HTML-elements that I used were shown with the markup.

For example: I used the <b>Test</b> elements in the textbox, and this was showed in a label as:

Test

But what I would like to have is, when someone adds HTML elements to my textbox, the error shouldn't appear, and the elements shouldn't be converted. So the label must show:

<b>Test</b> instead of Test (which is BOLD)

What can I do to make it like that?

Upvotes: 0

Views: 152

Answers (1)

Stephen
Stephen

Reputation: 2047

Use Server.HtmlEncode("<b>Test</b>")

Upvotes: 2

Related Questions