How to display an error message within the form

SearchForKnowledge

I have the following ASP.net page:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Tks.aspx.cs" Inherits="Dr.Tks" ValidateRequest="true" %>

<asp:TextBox ID="tbComments" ClientIDMode="Static" CssClass="tbTech" runat="server" TextMode="MultiLine" Columns="30" Rows="15"></asp:TextBox>
<asp:Button ID="SubmitForm" ClientIDMode="Static" runat="server" Text="Submit" OnClick="ValidateForm" CssClass="btnFancy orange logBtn btnLogIn lightLinks" UseSubmitBehavior="false" />

C#:

public void ValidateForm(object sender, EventArgs e)
{
    try
    {
        string strTheBody = HttpUtility.HtmlEncode(tbComments.Text);
    }
    catch (Exception)
    {
    }
}

If I enter <script... in the textbox above, I get the following error:

Server Error in '/' Application.
--------------------------------------------------------------------------------
A potentially dangerous Request.Form value was detected from the client (tbComments="<script...").

How can I validate the textbox as I type, rather than display the default error message from ASP.net (which is not user friendly)

Angus Chung

In .NET 4.5 , you can set ValidateRequestMode="Disabled" on a control.

<asp:TextBox ID="tbComments" ValidateRequestMode="Disabled" ClientIDMode="Static" CssClass="tbTech" runat="server" TextMode="MultiLine" Columns="30" Rows="15"></asp:TextBox>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to display an error message for a specific time period within ReactJS?

How to return and display an error message from within a exception try catch

How to display an error message when a field is empty in a native script form?

How to display an error message with react hook form in a useFieldArray

How to display the summary of error message on top of the form in angular reactive forms

How to display a mat-error message without a form control, but with matInput?

Display form error message on form page

How to display the error message

display error message after submitting a form

Rails Form_with display inline error message

How to display Custom Validation error message using "app-form-group-control-validation-display" in angular 4

form action is another page(php code) how to validate the form and display error message in view page

How to display the error message for DataAnnotations

How to display error message in Highcharts?

how to display openerp error message

How to show error message in the form

display error message on form if the message is not empty angular 2

How to display message when a user submits the form

How to display alert message after submitting form

How to display Django friendly forms.ValidationError/message.error before form.save?

Form validation display same error message for all fields

Display mat-form-field error message before control is touched

Display error login message on custom spring boot login form

Using thymeleaf to display an error message alters the layout of my login form

Django forms - unwanted error message on first display of the form

Display form validation error message on same page using only PHP?

Check if the website exists and if not then display Error message under the Form Input Field

How to display assertion error message in dashboard report?

How to not display browse widget error message?