Customvalidator Error Messages Validation Summary
Contents |
here for a quick overview of the site Help asp.net custom validator error message not displaying Center Detailed answers to any questions you might have
Add Message To Validationsummary
Meta Discuss the workings and policies of this site About Us Learn more about Stack add error to validationsummary from code behind Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask asp.net validationsummary Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Elegant way to make CustomValidator work with ValidationSummary messagebox up vote 18 down vote favorite
Asp Custom Validator
7 I have run into this problem before but never quite solved it. I have a form with several validators and also a CustomValidator.
ASP.NET Community Standup Forums Help Home/ASP.NET Forums/General ASP.NET/Web Forms/How to show error mesage from "CustomValidator" to "ValidationSummary... How to show error mesage from "CustomValidator" to "ValidationSummary" control? RSS 8 replies Last post Apr 14, 2005 12:06 PM by PLBlum ‹ Previous Thread|Next Thread › Print Share Twitter Facebook Email Shortcuts Active Threads Unanswered Threads Unresolved Threads Support Options Advanced Search Related Links GuidanceSamplesVideos Reply bosox04 None 0 Points 71 Posts How to show error mesage from "CustomValidator" to "ValidationSummary" control? Apr 12, 2005 04:34 PM|bosox04|LINK Hello All, I have an aspx page with several "requiredfieldvalidator" and one "customvalidator" for the http://stackoverflow.com/questions/811734/elegant-way-to-make-customvalidator-work-with-validationsummary-messagebox checkbox. I use a "ValidationSummary" with the ShowMessageBox="true" to display a popup summary of all required fields. All error message from "RequireFieldValidator" are shown accordling, but not the error message from "CustomValidator". Anyone know why? and how to correct it? Thanks Reply daver None 0 Points 178 Posts Re: How to show error mesage from "CustomValidator" to "ValidationSummary" control? Apr 12, 2005 06:06 PM|daver|LINK I assume your custom http://forums.asp.net/t/875239.aspx?How+to+show+error+mesage+from+CustomValidator+to+ValidationSummary+control+ validator is doing server side work to determine the validity of the data, correct? If so, once you determine that the data is invalid, add the custom validator to you validation summary in your code behind. -- daver Reply ahooi99 None 0 Points 165 Posts Re: How to show error mesage from "CustomValidator" to "ValidationSummary" control? Apr 12, 2005 10:20 PM|ahooi99|LINK You can write your CustomValidation logic in client side by using the javascript. Then for your CustomValidator, set the ClientValidationFunction to your javascript function. It works as RequiredFieldValidator, without causing any postback.. [:)] -- Tough People Do Tough Task -- Reply bosox04 None 0 Points 71 Posts Re: How to show error mesage from "CustomValidator" to "ValidationSummary" control? Apr 13, 2005 09:13 AM|bosox04|LINK Daver, yes I use server side for my custom validator. How do I add the custom validator to my ValidationSummary control? Reply bosox04 None 0 Points 71 Posts Re: How to show error mesage from "CustomValidator" to "ValidationSummary" control? Apr 13, 2005 11:30 AM|bosox04|LINK ahooi99, do you have any samples? Reply daver None 0 Points 178 Posts Re: How to show error mesage from "CustomValidator" to "ValidationSummary" control? Apr 13, 2005 11:59 AM|daver|LINK ahooi99, nice - I didn't kno
Summary control.So i expect it to show a messagebox when my custom validation fails.For testing purpose in my servervalidate event handler of https://www.sitepoint.com/community/t/customvalidator-and-validationsummary-control-issue/1277 CustomValidator i made the ServerValidateEventArgs.IsValid to false.So i expect the validation https://blogs.msdn.microsoft.com/simonince/2008/02/28/adding-messages-to-a-validation-summary/ to fail and show a messagebox,everytime i enter some valuse in my text box and click on the button .But the messagebox is not displayed and to add to my confusion if i set the ShowMessageBox=false and ShowSummary=true the validation summary report is custom validator shown properly.So how can i display the messagebox if my customvalidation fails.is this a bug with controls or am i missing anything here?I don't want to make this posting bulky,so will post the code if itz of some use. Someone pls help me out to fix this problem. Thanxngmtech jofa 2003-01-26 13:02:04 UTC #2 Yep, validator error message this is weird, and the ridiculous answer to the question is; the function that displays the alert() isn't called if you post the form using Enter in a textbox for example - if you click the Submit button, then it's working(Must be some way to change the page to call Page_ClientValidate() on onsubmit for the form) If this explanation doesn't apply to your problem, check that EnableClientScript is set to true Edit:I noticed this: "...in my servervalidate event handler..."Don't you mean ClientValidationFunction ?It's a bit difficult to pop up a message box from the server ngmtech 2003-01-27 08:22:08 UTC #3 thanx for the reply.But i am not using any client side validation for custom control.I am using the ServerValidate event(As per MSDN The ServerValidate event is raised when validation is performed on the server) of custom validator to perform checking against database and for testing purpose(to show messagebox) am setting IsValid to false all the time so that Messagebox of valdatio
J InceFebruary 28, 200819 0 0 0 For a while now I’ve used this handy bit of code to add a message programmatically to a Validation Summary control, without associating it with a Validator. I’ve no idea where it came from – perhaps my head, perhaps someone cleverer than I… so if it was from you, shout up! I was asked how to do this today by a customer, so I felt inspired to blog it. Anyway, sometimes you get an error from your business logic that it just isn’t practical to have pre-validated. For example, when adding a new employee to a database, perhaps the employee name has a UNIQUE constraint on it. Validating this up front might not be easy… So if I get an error back from my business logic (either in the form of a list of validation errors, or in the worst case scenario as an exception) how do I display this message to the user? Well it turns out this is quite easy – just add a validator that is reporting itself as “IsValid = false” to the Page.Validators collection. Consider the following class; public class ValidationError : IValidator { private ValidationError(string message) { ErrorMessage = message; IsValid = false; } public string ErrorMessage { get; set; } public bool IsValid { get; set; } public void Validate() { // no action required } public static void Display(string message) { Page currentPage = HttpContext.Current.Handler as Page; currentPage.Validators.Add(new ValidationError(message)); } } (Note: This is usingautomatic properties - a C# 3.0 feature. Alter the code to use standard properties if you're using an earlier version of .NET) This immediately allows me to use the following code; ValidationError.Display("Oops, some error occurred."); Succinct, eh?! Here’s a shot of it in action;
Tags ASP.NET C# Comments (19) Cancel reply Name * Email * Website Jason says: February 29, 2008 at 12:07 pm Thanks for this. It definitely came in useful for me. Reply KA says: March 28, 2008 at 1:15 pm This works well - thanks for the tip. Reply Nicole says: April 7, 2008 at 2:06 pm Something similar to this can be done by adding a CustomValidator dynamically when