how to display only single message for multiple RequiredFieldValidators?
Asked Answered
L

9

12

how to display only single message for multiple RequiredFieldValidator instead of individual message for RequiredFieldValidator ?

i want to as shown in following image..

i want to as shown in following image..

my view is..

 my view is.

Laxative answered 12/1, 2012 at 12:3 Comment(1)
I was looking for a solution myself. Found this link to be the most useful: codeproject.com/Tips/72380/…Donelson
D
13

You will have to use ValidationSummary control for this. See this ValidationSummary Class MSDN article for details and example on how to do this. This article contains an example of what you are trying to figure out exactly.

Depside answered 12/1, 2012 at 12:7 Comment(4)
thanks , but i have used ValidationSummary. but it shows multiple messages for each validator. and i want to display only single message for each validator. how can i?Laxative
you will have to hide each error message using Display="none" for each requiredfieldvalidatorDepside
but it hides the whole validator.!! if control is blank then this validator will not workLaxative
Set ErrorMessage to blank for each requiredfieldvalidatorDepside
O
5

set the HeaderText to something like "(*) Fields are required" to your validation summary.

Oriole answered 12/1, 2012 at 12:49 Comment(1)
thanks. but it also shows the RequiredFieldValidator's message. how can i hide it?Laxative
R
5

you can leave error message field of each RequiredFieldValidator blank and put * in text field, then add ValidationSummary defining its header text with error msg this will works for your scenario.

<asp:RequiredFieldValidator ID="RequiredFieldValidator_overhead_name" runat="server" ControlToValidate="TextBox_overhead_name">*</asp:RequiredFieldValidator>


 <asp:ValidationSummary ID="ValidationSummary_overhead_estimate" runat="server" DisplayMode="SingleParagraph" HeaderText="please insert data into fileds" /> 
Referent answered 14/12, 2012 at 10:26 Comment(0)
G
3

This gentleman solved it here quite simply: http://www.cactusoft.com/blog_40

Genagenappe answered 18/6, 2013 at 1:25 Comment(0)
F
3

Quick and easy way: add a CssClass to the ValidationSummary, then a css style that sets ul elements under that class to display: none.

For example:

<style>
.validationSummary ul {display:none}
<stlye>

...

<asp:ValidationSummary CssClass="validationSummary" ...
Fourflusher answered 12/2, 2016 at 18:22 Comment(0)
E
2

I can see what you are trying to do but it's difficult with the ASP.Net validators

The only way I can think to do it is remove the ValidationSummary altogether and manually create your own using the ASP.Net validator API and JQuery i.e.

  1. Change all required validators to ErrorMessage = "*" Remove Text value
  2. Remove Validation Summary
  3. Add a label at the bottom to function as a custom validator summary. Style it red
  4. In the page markup script something like
if(!Page_IsValid) {    
    $('#myCustomValidatorSummary').text('Please fill in required fields')
}

Page_IsValid is from the ASP.Net validator API. Set to false if the page fails validation.

Of course this assumes that you only have the required field validators on your form. If there is a mix then you will need to check if one or more of the required ones have failed by iterating through the Page_Validators on the client using JQuery/javascript

Honestly though I wouldn't do it - it's too hard

I would just do this - For each required field validator - set

Text="*" 
ErrorMessage="[Field Name] is mandatory. Please supply a value." or similar.
Experiential answered 12/1, 2012 at 13:6 Comment(0)
G
1

You should use the ValidationSummary Control from ASP.NET in addition to ValidationSummary you could also use the Group property to separate controls into logical groups. See http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.validationsummary.aspx for a bunch of examples.

Gumbo answered 12/1, 2012 at 12:10 Comment(0)
D
0

use ValidationSummary

The ValidationSummary control is used to display a summary of all validation errors occurred in a Web page.

The error message displayed in this control is specified by the ErrorMessage property of each validation control. If the ErrorMessage property of the validation control is not set, no error message is displayed for that validation control.

http://asp-net-example.blogspot.in/2008/10/validationsummary-example-how-to-use.html

Doghouse answered 9/3, 2012 at 10:49 Comment(0)
S
0

To add to Mike Godin's answer, for only showing a single alert message for multiple field validators:

Keep individual required messages. Add Validation Summary with DisplayMode="BulletList" and HeaderText="Please provide the required information above."

The "BulletList" display mode produces a unordered list of LI's inside the Validation Summary DIV, then hide UL via styling - only the "HeaderText" will show:

    #validationSummary ul {
        display:none;
    } 

<asp:ValidationSummary 
     id="validationSummary" 
     DisplayMode="BulletList"
     EnableClientScript="true"
     HeaderText="Please provide the required information above."
     ValidationGroup="btnSubmit"
     runat="server"/>
Settlings answered 28/11, 2016 at 16:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.