Amit Shah
Amit Shah

Reputation: 327

Allowing HTML text in asp textbox w/o using validateRequest=false


Is it possible to send a html text entered in asp.net text box without making validaterequest to false.
Thanks,
Amit Shah

Upvotes: 1

Views: 1320

Answers (2)

ajbeaven
ajbeaven

Reputation: 9562

Control.ValidateRequestMode, new to .NET 4.5, might be of interest to you. It allows you to specify how individual controls are validated.

Upvotes: 0

Dave Thieben
Dave Thieben

Reputation: 5427

You could probably add some javascript to encode the textbox value before the form is submitted.

something like:

$(function() {
  $("form").submit(function() {
    var myTextBox = $("#myTextBox");
    myTextBox.val( encodeMyHtml( myTextBox.val() ) );
  });
});

function encodeMyHtml(encodedHtml) {
  encodedHtml = escape(encodedHtml);
  encodedHtml = encodedHtml.replace(/\//g,"%2F");
  encodedHtml = encodedHtml.replace(/\?/g,"%3F");
  encodedHtml = encodedHtml.replace(/=/g,"%3D");
  encodedHtml = encodedHtml.replace(/&/g,"%26");
  encodedHtml = encodedHtml.replace(/@/g,"%40");
  encodeHtml.htmlEncoded.value = encodedHtml;
} 

Upvotes: 2

Related Questions