Validation Problem

I have a page where I use validation validation and the necessary fields for validation. When I click the validation confirmation button, a message with a message written in the required field validators is displayed in the validation manager. I want to display another message in the validation summary and required field validators. for example, validation should display "a field marked with a" required "sign, and a mandatory field validator should display only" * ".

thanks

+4
source share
3 answers

Set the validator Text property to "*". This will be displayed in the validator text if validation fails and ErrorMessage will be displayed using the validation summary.

+9
source

Pankaj try this code ...

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Error" ControlToValidate="TextBox1">*</asp:RequiredFieldValidator> <br /> <asp:ValidationSummary ID="ValidationSummary1" runat="server" DisplayMode="List" /> </div> <asp:Button ID="Button1" runat="server" Text="Button" /> 

Here I set the DisplayMode property of the check summary for List

+1
source

For someone looking for how to do this - just like me, this works for me using MVC4:

Model:

  [Required(ErrorMessage="*")] public string Name { get; set; } 

CSS

 .validation-summary-errors ul { display: none; } 

Presentation Form:

<% using (Html.BeginForm ("Send", "Contact")) {%> <% - <%: Html.ValidationSummary (false, "Fields marked with * are required", new {@style = "display: none"} )%> -%> <%: Html.ValidationSummary (false, "Fields marked with * are required")%>

  <div class="editor-label"> <%: Html.LabelFor(model => model.Name) %> </div> <div class="editor-field"> <%: Html.EditorFor(model => model.Name) %> <%: Html.ValidationMessageFor(model => model.Name) %> </div> <p> <input type="submit" value="Send" /> </p> </fieldset> <% } %> 
0
source

Source: https://habr.com/ru/post/1300013/


All Articles