Is it possible to send a html text entered in asp.net text box without making validaterequest to false.
Thanks,
Amit Shah
-
Have you tried using Server.HTMLEncode() on the contents of the textbox?SoftwareGeek– SoftwareGeek2010-07-24 16:26:09 +00:00Commented Jul 24, 2010 at 16:26
Add a comment
|
2 Answers
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;
}
1 Comment
Dave Thieben
I should add that the user will probably see the value of the textbox change into the encoded value while the form is submitting.
Control.ValidateRequestMode, new to .NET 4.5, might be of interest to you. It allows you to specify how individual controls are validated.