I want to add a validator which prevents the html injection on Asp.Net injection. I am using the below code :
<asp:TextBox ID="TxtBoxMultiLine" runat="server" TagName="textBoxValidation" Width="50%" AutoPostBack="False" autocomplete="off" textMode="MultiLine"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="HTML Tags Not Allowed" ControlToValidate="TxtBoxMultiLine" ClientValidationFunction="ValidateTitle" ValidationGroup="htmlValidation"></asp:CustomValidator>
<asp:Button Text="Save" ID="addSaveBttn" CssClass="savesimpleshape1" runat="server" OnClick="addSaveBttn_Click" ValidationGroup="htmlValidation"/>
i am using that javascript function to validate my textbox.
function ValidateTitle(event) {
str = (document.getElementById('textBoxValidation')).value;
if (str.match(/([\<])([^\>]{1,})*([\>])/i) == null) {
event.IsValid = true;
}
else {
event.IsValid = false;
}
}
When i pressed the button occurs that exception : A potentially dangerous Request.Form value was detected from the client
It seems that is ignoring my validation. Also, i don't want to put this element : ValidateRequest = false on my page.