how to display only single message for multiple RequiredFieldValidator
instead of individual message for RequiredFieldValidator
?
i want to as shown in following image..
my view is..
how to display only single message for multiple RequiredFieldValidator
instead of individual message for RequiredFieldValidator
?
i want to as shown in following image..
my view is..
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.
set the HeaderText to something like "(*) Fields are required" to your validation summary.
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" />
This gentleman solved it here quite simply: http://www.cactusoft.com/blog_40
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" ...
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.
ErrorMessage = "*"
Remove Text valueif(!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.
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.
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
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"/>
© 2022 - 2024 — McMap. All rights reserved.