Home »
Code Examples »
ASP.Net Code Examples
ASP.Net - A potentially dangerous Request.Form value was detected from the client Code Example
The code for A potentially dangerous Request.Form value was detected from the client
// The exception occurred when any input text has some special characters
// like less than (<), greater than (>), single quote ('), etc.
// Make the changes on both of the pages (asp) and code behind (on_load)
// Before closing </asp:content>, insert this JS
<script language="javascript" type="text/javascript">
function encodeMyHtml(toEncode) {
return toEncode.replace(/&/gi, '&').replace(/\"/gi, '"').replace(/</gi, '<').replace(/>/gi, '>');
}
</script>
' on_load (Bind those input boxes) - vb code
BtnCodeSubmit.Attributes.Add(
"onclick",
"this.form." + TxtName.ClientID + ".value = encodeMyHtml(this.form." + TxtName.ClientID + ".value);"
)
Code by IncludeHelp,
on August 11, 2022 23:20