IValidatableObject.Validate Only Called If Property Validation Passes?
Jan 22, 2011
In my model, it seems that Validate() is only called AFTER both properties pass validation.
public class MyModel : IValidatableObject
{
[Required]
public string Name { get; set;}
[Required]
public string Nicknames {get; set;}
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if(Nicknames != null && Nicknames.Split(Environment.NewLine.ToCharArray()).Count() < 2)
return yield result new ValidationResult("Enter at least two nicknames, new [] { "Nicknames" });
}
}
When a user enters a single line of text in the Nicknames text area but leaves the Name text box empty, only the Required error message for the Name property is displayed. The error message that should be displayed from the Validate() function never shows up.
Only after entering a name in the Name text box and some text in the Nicknames text is the Validate() function called.
Is this how it's supposed to work? It seems odd that a user is shown an error message on a subsequent page when the error is being caused on the current page.
View 1 Replies
Similar Messages:
May 17, 2010
Can you validate just a single property with the Fluent Validation Library, and if so how? I thought this discussion thread from January of 2009 showed me how to do it via the following syntax:
validator.Validate(new Person(), x => x.Surname);
Unfortunately it doesn't appear this works in the current version of the library. One other thing that led me to believe that validating a single property might be possible is the following quote from Jeremy Skinners' blog post:
"Finally, I added the ability to be able to execute some of FluentValidation's Property Validators without needing to validate the entire object. This means it is now possible to stop the default "A value was required" message from being added to ModelState. "
However I do not know if that necessarily means it supports just validating a single property or the fact that you can tell the validation library to stop validating after the first validation error.
View 1 Replies
Feb 14, 2010
I am uploading a JPEG image in an ASP.NET MVC web site.
The model validation fails in IE, but passes in Firefox, when I try to check the mime type of the
HttpPostedBaseFile.
So I debuged it and I found that when using Firefox the Mime type is "image/jpeg" as expected.
When using IE8 the mime type is "image/pjpeg".
Don't say that Microsoft invented a new Mime Type of JPeg images?
View 3 Replies
Aug 28, 2010
Custom Validation Attribute is not called by validation mechanism?
[Code]....
ViewModel
[Code]....
View 3 Replies
Nov 8, 2010
I have a simple 2 tab panel setup with 2 validation groups. My problem is that my buttons fire both validation groups.
<cc1:TabPanel ID="TP2" runat="server" HeaderText="" Enabled="true">
<HeaderTemplate>Loan Main</HeaderTemplate>
<ContentTemplate>
[code]...
View 1 Replies
Mar 18, 2011
I am using a wizard control in which I have a next button that has causes validation = true. I also have a checkbox that when changed, in the event handler, I set causes validation = false for the next button. When that button is clicked - I get the following:
Page.IsValid cannot be called before validation has taken place. It should be queried in the event handler for a control that has CausesValidation.
Here is the code:
protected void chk_CheckChanged(object sender, EventArgs e)
{
CheckBox chk = (CheckBox)sender;
ImageButton ibtnStepNext = (ImageButton)(this.WizardSummaryTemplate.CustomNavigationTemplateContainer.FindControl("StepNextButton"));
ibtnStepNext.CausesValidation = (!chk.Checked);
}
What would be the recommended solution to disabling validation for the next button so I don't see this error?
View 1 Replies
Mar 16, 2011
I'm trying to extend the requirefieldvalidator to take a new property and validate regularexpressions also. I know I can use the RegularExpression control but then i need 2 controls so i want to eliminate it so i only have to use two controls. There are also other features i want to make which include me extending it. My problem is i don't know what to override - i tried the Validate() but i get "cannot override inherited member 'System.Web.UI.WebControls.BaseValidator.Validate()' because it is not marked virtual, abstract, or override" and i understand the EvaluateIsValid() is for validating the control not what is in the control.
[code].....
View 2 Replies
Oct 4, 2010
I am using javascript to validate user input on my aspx page. I am easily able to validate textboxes and dropdown list for differenet scenarios.
Now, on one of my dropdown lists (for country), I need to check if it is an allowed country or not for a particular service. I have stored the valid country list in a static property. Is there a way to validate my dropdownlist selected value against that static property?
function validateService(source, args)
{
var country = document.getElementById('<%= ddDestCountry.ClientID %>');
var service = document.getElementById('<%= ddService.ClientID %>');
// Get allowed country list from my static class
var countryList = document.getElementById('<%= StaticProperties.EUCountryList %>');
if (service.value == "P")
{
// I want to do something like this
if (!countrylist.Contains(country.value))
{
args.IsValid = false;
}
else {
args.IsValid = true;
}
}
return;
}
Update(Additional Information): The static property is read-only so it cannot be tampered with from the page.
View 1 Replies
Mar 13, 2010
VWD 2008 Express. Visual Basic.
I have two validationsummary controls on my page for aesthetic reasons. Each control is assigned a validation group (StudentInfo and Grades). validation controls in the upper part of my page are in validationgroup StudentInfo and those in the bottom part of my page are in validationgroup Grades.
However, I only have one "Save" button control that causes validation. I want the Save button to validate both groups of controls, but it appears to only allow one Validation group to be specified in its properties.
Is there a way to have a button cause validation for both groups?
View 2 Replies
Mar 14, 2011
I have a Form like this.
UserID has to be validated when user clicks "Check Availability" and "Submit"
Hence "UserID" required field validator has to be assigned two grops.
As if now it is assigned only Group1
[code]....
I have already gone through How to validate against Multiple validation groups?
which talks about validating Group1 and Group2 when user clicks "Submit" which is a good alternate solution.
View 1 Replies
Mar 24, 2010
I have two validation groups: parent and child
I have an add button that needs to only validate the child validation group which is easily done. The save button needs to validate against the parent and child validation groups, both client side and server side. I think I know how to do it server side by calling the Page.Validate("groupname") method for each group, but how can it be done client side?
View 1 Replies
Jan 30, 2011
I got a Category model and it looks like this
[Code]....
My problem is that when i do a tryupdatemodel it validate the ParentCategory aswell, is it really suppose to do that? How could i avoid this, I tried [Bind(Excluede = "ParentCategory)] in the ActionResult but with no luck. I have looked all over the place with no luck everybody just got the Id problem.
View 1 Replies
Dec 25, 2010
When I use a compare validator, datatypecheck="String", and try to enter the following code to test, the comparevalidation doesn't catch it in time, and instead the browser pops up with an error saying the text is not allowed.
Will JavsScript validation catch it?
<link href="../Styles/StyleSheet.css" />
View 1 Replies
May 17, 2010
there I am using xval for the first time, it seems to work fine for required fields, However I am having some issues first of all it does not seem to validate booleans and also client validation is not working for me, this is not a major issue for me, the one that I really need to work is the stringlength property. It seems to do something because the form is not posted when the string length is exceeded, however no error message is displayed to the user which is obviously not what I want, has anyone been able to do this successfully?
My model goes like this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
namespace PitchPortal.Core
{
public class DocumentMetadata
{
//[Required]
// public bool visibility { get; set; }
[Required,StringLength(10, ErrorMessage = "title is too long")]
public string title { get; set; }
[Required, StringLength(10, ErrorMessage = "description is too long")]
public string description { get; set; }
[Required, StringLength(10, ErrorMessage = "summary is too long")]
public string summary { get; set; }
[Code]....
View 1 Replies
Nov 2, 2010
How Can We Check The Validation Of RadCaptcha From Code Behind - With Custom Validator(ServerValidate) / WithOut Using And Setting ValidationGroup ?
View 2 Replies
Mar 10, 2011
I'm working on a very dynamic site build at the moment. What I'm trying to do is creating something like a survey that can be created dynamically from a control panel. In the control panel you add input fields (these are saved in a database), what the user then see is a form that I generate from the database. So if I add 3 input fields to the database the survey will contain 3 fields. If I add 20 fields the survey will have 20 fields.
Now my problem is that I want to validate these fields, and I would like to be able to hook me in with the standard validation flow. I can't create a Model with validation rules since the number of fields and their names are dynamic the only thing I know is what kind of data that is expected in every field (this rule is found in the database). In an ordinary case I would get the automatic highlighted fields that are not valid and so on thanks to the built in validation flow with ValidationResult and so on.
So the question now is can I somehow simulate parts of the validation and then hook me back in with the validation result, and if not valid, the form prints the error messages and fill the fields with the data that was given?
View 1 Replies
Jun 5, 2010
I just began to look into custom server controls a couple days ago, and while I'm happy with my progress overall, I'm stuck on an issue.
Conditional.cs
[code]....
EDIT 2: It seems that the problem now is that I cannot set a parameter with a databound value before the control is initialized
<cv:conditional id="condTest" runat="server" selector='<%# DataBinder.Eval(Container, "DataItem") != null %>'>...
View 6 Replies
Jul 23, 2010
i have imported data from excel to datatable but i need to validate port no column which should
allow only numeric value and also i need to check the single quotes and need to replace to double quotes.
View 2 Replies
Aug 10, 2010
am trying to use JQuery validation plugin to validate some fields on one page.at page also has a link button which submits the page to server. Now the problem that I am facing is jQuery validator doesn't fire when I submit the page with that link button. If I change the link button to normal button or image button then validation works fine. I can't change the control on the page and have to use the link button.
View 2 Replies
Mar 4, 2010
I am using below code to validate interger and float in asp.net but if i not enter decimal than it give me error
<asp:TextBox ID="txtAjaxFloat" runat="server" />
<cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" TargetControlID="txtAjaxFloat" FilterType="Custom, numbers" ValidChars="." runat="server" />
i have this regex also but its giving validation error if i enters only one value after decimal. [URL]
View 4 Replies
Mar 28, 2011
how can i validate a textbox with 5 number only are allow to fill in and first number must number 3. For example like 3XXXX,3YYYY (X and Y are number).
View 2 Replies
Mar 7, 2011
I have two validation groups 'Sub' and 'Normal'and i have some checkboxes . .
I need to validate depending on value of checkbox how to do this . .
View 5 Replies
Apr 1, 2010
I need to be able to validate multiple validation groups with the click of one button. My Form consists of two text boxes and a drop down list for input. The form also, currently, has three buttons, one for each control. Each of those buttons are tied to a validation control and if the validation is successful, it will add the user inputted data into a database that I have. The interesting part comes when I need to add a forth button which will act as a "Save All" Button. When this button is clicked, I need it to fire the three validation groups.
Is it possible to add multiple validation groups to the "Save All" Button?
View 2 Replies
Jan 28, 2014
I have repeater control which contains checkbox. when user click on download button I want to check whether user select atleast on checkbox using javascript not jquery.
View 1 Replies
May 7, 2015
I have a Dynamic GridView on a page as below. The user can add or delete rows. When inserting record, the code is executed one row at a time. I have 3 rows to be inserted to the database. Here is the issue:
-if the first row is not completed, then no record is added to the database
-if the first row is completed and the second row is not, then only the first row is inserted in the database
-if the first row is completed, the second row is not complete, and the third row is completed, then only the first row is inserted in the database.
below is the code:
protected void GridView1_AddNewRecord(object sender, EventArgs e)
{
string constr = ConfigurationManager.ConnectionStrings["DatabaseVestConnectionString1"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
SqlCommand cmd;
string query1 = "INSERT INTO kart_Bestilling(SakBehandlingCode, KystverketRegionID, KystverketAvdelingID, BestillerReferanse, BestillerLeveringAdresse, BestillerPostKodeBy, BestillerNavn, BestillerStilling, BestillerEpost, BestillerTelefon, BestillingBeskrivelse, BestillingDato, BehandlingSakNummer, BehandlingBeskrivelse, BehandlingStatus)" +
[code]...
How to arrange this piece of code to validate all rows before any insert? or avoid inserting a row if there is one row not complete?the conditions starts with int rowIndex = 0;
if (txtBestillerReferanse.Text != "" && txtBestillerEpost.Text != "" && txtBestillerNavn.Text != "" && txtBestillerPostKodeBy.Text != "" && ddKartTypeName.SelectedValue != "Velg KartType" && ddKartNummerName.SelectedValue != "Velg KartNummer" && tBestillingAntallKart1.Text != "")
View 1 Replies