.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

firing Validation rules under One way binding Mode

Posted By:      Posted Date: October 14, 2010    Points: 0   Category :WPF

Can Validation Rules fire When binding Mode is set to OneWay.?

If No : Is is Because the validation rules fire only when the source property changes and hence under oneway binding the source never changes and so the rules never fire.

Is there a workaround to Fire the validation rules Except invoking the explicitly.( Because i have triggered the save button to be enabled only when ther's no validation errors, So makin the user click and explicitly firing rules is not what i want.)



View Complete Post

More Related Resource Links

Help on Binding validation rules

Dear all, I have the follwoing code snipet: <TextBox Validation.ErrorTemplate="{StaticResource validationTemplate}" Style="{StaticResource textBoxInError}" Grid.Column="1" Grid.Row="3"> <TextBox.Text> <Binding Path="CurrentPlayer.Email" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged"> <Binding.ValidationRules> <vrules:EmptyStringValidationRules /> </Binding.ValidationRules> </Binding> <TextBox.Text> </TextBox> </Border> <Button Margin="1" Foreground="Black" FontSize="25" Grid.Row="5" Grid.Column="1" HorizontalAlignment="Stretch" Command="{x:Static local:QuizzCommands.Start}" Content="{StaticResource Ok}" /> From teh sample above I have place only a single text box but in fact I have 4 text box which should not be empty before pressing the button So in an other hand the Button should not be enabled until all text box entrie are filled by user I have impleneted a validation rules which check if filed is empty as follow : class EmptyStringValidationRules:ValidationRule { public overri

Input Validation: Enforcing Complex Business Data Rules with WPF


Windows Presentation Foundation has a rich data binding system that includes flexible support for business data validation. We take a look at implementing some complex data input validation scenarios that include customized data errors for users.

Brian Noyes

MSDN Magazine June 2010

Web Services: Extend the ASP.NET WebMethod Framework with Business Rules Validation


In an earlier article the authors showed how to build a custom WebMethods extension that provides XML Schema validation, a function that is lacking in ASP.NET. In the process they established a foundation for enforcing business rules during the deserialization of XML data. The technique, which is described in this article, uses declarative XPath assertions to test business rule compliance.In building this business rules validation engine, the authors integrate the validation descriptions into the WSDL file that is automatically generated by the WebMethod infrastructure. Finally, they demonstrate how to extend wsdl.exe, the tool that generates WebMethod proxy/server code from WSDL files, to make use of their extensions.

Aaron Skonnard and Dan Sullivan

MSDN Magazine August 2003

Binding of complex entity turns into validation error

consider classic example: Product and Category editing Product in dropdown Id of Category is selected - Category mapped as object with all fields empty except Id when submitting Product edit form - validation gives an error: "Category name is required" (I have Required attribute on Category Name property) How deal with such errors if I want to use built-in validation (if (!ModelState.IsValid))? Writing custom data binder which would fill all such id-only-objects with values from database comes to mind.upd: I did small research of mvc code and found out that validation happens before binding - so this solution would't work. Do you have any other solutions for this problem?

Preventing selectedindex changed from firing on binding

When I bind a combo box to an object and it is initially displayed, I notice that the selectedindex changed event is being fired. I don't want this event to fire unless the control is changed interactively. Is there a way to prevent this from occurring or should I be using a different event? TIA

Which is the best approach for applying business rules and basic validation like data types?

Hi Everybody   Please suggest me the best approach for applying the business rules and data type validations .Here is my choices : 1)Sequential work flow 2)State machine work flow 3)Work flow rule engine 4)Rule engine without workflow Out of above choices ,which is the best approach? Please provide me the reasons or senarioes for which is the best approach for applying the business rules and also performancewise. My requirement is : After getting the reports ,need to apply the datatype validations like valid or invalid date ...etc to the reports .And stored into Database.In the next step,need to apply the business rules to that reports in such a way that data should be good quality. Thank you very much

Binding A ReadOnly DP with OneWayToSource mode, possible?


Hi guys,

I have a UserControl with a ReadOnly property.

Using MVVM, I want the View to be able to bind to the VM with a OneWayToSource mode.

But I get an error

The property cannot be set because it does not have an accessible set accessor.

Any idea for this issue?



Defining Validation rules with Data annotations - ???


I am having following problem:

Defined RegisterModel class - with some validation rules for creating new users, and this works fine.

Then I get this class, strip few properties and wanted to reuse it as UserInfo_Form_Model,   for editing user properites.

No changes, just deleted few items, renamed and reused in strongly typed View for editing.

And result of validation is: -

[DisplayName("Name")] works fine, showing correct

[StringLength(20, ErrorMessage = "xxxx...")] - not working, no message showed when suppose to be one

[Required(ErrorMessage = "xxxx.")] - not working, not showing messages when delete required values?

but  (ModelState.IsValid) is false when I checked it in controller (it had to be because required value is missing)?

Is it this only partially correct and how this can be?

Well this is a bit frustrating because it cant be simpler than this and I cant make this simple code reuse. :|

Quite a few gotchas I already found or I am coding completely wrong.

Problems with multiple validation rules



I've added some custom validation rules programatically like this:



            BindingOperations.GetBinding(txtTitulo, TextBox.TextProperty).ValidationRules.Clear();

            BindingOperations.GetBinding(txtTitulo, TextBox.TextProperty).ValidationRules.Add(new ReglaDatoRequerido(Idioma.RecursoIdiomaLocal(this, "msjErrorDatoRequerido")));

            BindingOperations.GetBinding(txtTitulo, TextBox.TextProperty).ValidationRules.Add(new ReglaRangoDatos(Idioma.RecursoIdiomaLocal(this, "msjErrorDatoRequerido"), 1, 5, false));

these are the rules:
public abstract class ReglaValidacionBase : ValidationRule
        /// <summary>
        /// Mensaje de error.
        /// </summary>
        public string MensajeError { get; set; }

   public class ReglaDatoRequerido : ReglaValidacionBase
        public ReglaDatoRequerido(st

Binding Mode OneTime is not working properly



I am binding a ListBox with Mode = OneTime as i want to bind it first time only , after that if data changes i dont want my listbox to take care of that

 <ListBox x:Name="_statusListBox"
           Background="Transparent" BorderThickness="0"
           ItemTemplate="{StaticResource StatusListBoxItemTemplate}" 
           ItemsSource="{Binding Summary.ProjectStatusSummary,Mode=OneTime}"

but it works randomly , somethimes it binds data and sometimes it does not

i want to know the reason of this random behavior



MVC3 : Validation parameter names in unobtrusive client validation rules must start with a lowercase


I am migrating my application to MVC3 and getting this error message

Validation parameter names in unobtrusive client validation rules must start with a lowercase letter and consist of only lowercase letters or digits.

How can I ovoid it without going and modifying all my ViewModels

Tank you for your help 

AJAX Validation callout extenders firing when other buttons are pressed


I have several buttons on a page, but have assigned some validators and AJAX validator callout extenders to one button in particular. However, the validator callout extenders seem to be firing even if I press a different button. I thought this was the point of setting a TargetControlID (for the valiator callout extender) and a ControlToValidate for the validator itself! Any suggestions as to what I'm doing wrong?

<asp:TextBox ID="tbNewDuration" runat="server" />   Duration <br />
<asp:RequiredFieldValidator ID="tbNewDurationRFV" ControlToValidate="tbNewDuration" ErrorMessage="Please enter a Duration value." Display="None" runat="server" />
<cc1:ValidatorCalloutExtender ID="tbNewDurationVCE1" runat="server"  TargetControlID="tbNewDurationRFV" />
<asp:RegularExpressionValidator ID="tbNewDurationREV" runat="server" Display="none" ControlToValidate="tbNewDuration" ErrorMessage="Please enter a number of 10 digits" ValidationExpression="^\d{10}$" />
<cc1:ValidatorCalloutExtender ID="tbNewDurationVCE2" runat="server" TargetControlID="tbNewDurationREV" />

Validation when adding a new item and no target to source binding has yet taken place


Using: WPF (.NET 4) with Entity Framework on a SQLCE database.

In my app, the user can edit existing employees and create new employees. The same UI control is used to add and edit. In the case of editing an Employee, the DataContext for the control is the Employee object of my Entity Framework context. It is updated through binding, and the SaveChanges method is called on my EF to update the database. In the case of adding and Employee, the DataContext is a new Employee object, which will gets added to the EF and then saved. Simple.

I've been trying to hook-up validation to the control. I'm using WPF's ValidationRule objects for each field binding as required. When the field loses focus (as is the default action for a target to source binding), the validation rules are checked, which can incur an error. I can then check for the presence of these errors before allowing the employee to be saved.

But when adding a new Employee, if I go ahead and push the Save button without doing anything else, no validation takes place, becasue the bindings have never attempted to update the source! It just throws an exception as expected.

What can I do? I have ideas which would probably work, but I thought I should post here first in case I am missing something obvious! Is there a standard way to deal with t

Server validation is not firing if submited by Jquery $.ajax method


I am new in MVC.Using MVC2.MY create view is given below...

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcApplication1.Models.ExpenseCategory>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script src="<%=ResolveUrl("~/Scripts/jquery-1.4.1.min.js")%>" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
        function SaveExpenseCategory() {
            try {

                var requrl = "/ExpenseCategory/Create";
                var formID = "frmAddEC";
                var serdata = $(frmAddEC).serialize();


Binding WPF Controls to an Entity Data Model

In this interview, programming writer, McLean Schofield, demonstrates how to bind WPF controls to an entity data model, using Visual Studio 2010 Beta 1. You can also learn more in the topic: Walkthrough: Binding WPF Controls to an Entity Data Model.

Binding the multiple drop down boxes in GridView using JQuery in ASP.NET

Here is the code for binding the multiple drop down boxes in GridView using JQuery in ASP.NET

Binding WPF Controls to an Entity Data Model

In this interview, programming writer, McLean Schofield, demonstrates how to bind WPF controls to an entity data model, using Visual Studio 2010 Beta 1. You can also learn more in the topic: Walkthrough: Binding WPF Controls to an Entity Data Model.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend