.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

Problems with multiple validation rules

Posted By:      Posted Date: September 24, 2010    Points: 0   Category :WPF


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

View Complete Post

More Related Resource Links

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

Multiple forms on the same page MVC2: how to handle (including validation from model)



It should be simple; although I'm having a hard time to figure out the best way to do it. I've MVC2 pages with multiple forms on the same page having different functionalities.

What's the best way to handle this; including the MVC2 way of validation from the model?


DataGrid ValidationRule or IDataErrorInfo validation code called multiple times for each data change

Following my enquiry regarding a problem in Datagrid validation, for which managing exceptions is apparently a problem, I tested the two other methods: using validation rules, or implementing the IDataErrorInfo interface. I ran into other problems there, more insidious this time. This has been done on Windows7 (32-bit), .NET 4.0.30319. 1) IDataErrorInfo When this interface is implemented, the this[string columnName] property is called four times for each modification: two times before the cell enters edit mode (with the old value in the corresponding property) two times when the new value has to be validated (with the new value) It strikes me as not really efficient, is there something wrong with my code? Here's the C# part: using System; using System.Windows; using System.Collections.ObjectModel; using System.ComponentModel; namespace DataGridTest2 { public partial class MainWindow : Window { ObservableCollection<User> users; public MainWindow() { InitializeComponent(); users = new ObservableCollection<User>() { new User { Name = "Teddy", Age = "2" }, new User { Name = "Avi", Age = "19" } }; datagrid.ItemsSource = users; datagrid.Focus(); } } public class User : INotifyPropertyChanged, IDataErrorInfo { string name; public string Name

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

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

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 calls from the same client


Hi all!

I have a service with the following binding configuration (identical on server and client), running under IIS (Win 7 x64):

 <binding name="Printec.TMS.DCS.WindowsTcpBinding" maxReceivedMessageSize="6553600" 
  maxConnections="2000" listenBacklog="2000" closeTimeout="00:10:00" 
  sendTimeout="00:10:00" receiveTimeout="00:10:00" openTimeout="00:10:00">
 <readerQuotas maxDepth="200" maxStringContentLength="6553600" maxArrayLength="6553600" />
 <reliableSession enabled="false" />
 <security mode="None" />

Here is the service behaviour:

<behavior name="ServiceBehavior">
 <dataContractSerializer maxItemsInObjectGraph="

Problems with XmlDsigEnvelopedSignatureTransform and multiple signatures


 I'm having a lot of problems using XmlDsigEnvelopedSignatureTransform when signing an XML document multiple times. For example, I have a simple document and I add a signature to it, then, when I check the document, the signature is valid and everything is fine. But when I add a second signature to the previously signed XML then the problems begin: the second signature is valid, the first one not! This seems like if the XmlDsigEnvelopedSignatureTransform is not removing the already existing Signature nodes (as from W3C specifications) from the document before signing and when verifying, so the second signature broke the first one. This behavior is also specified in the MSDN documentation:

The XmlDsigEnvelopedSignatureTransform class removes the <Signature> element from an XML document before the digest is computed. With this transform, you can sign and verify all elements of an XML document except the XML digital signature elements. 

To confirm this, I've tested the example found in the official documentation and the results are like I imagined, the Signature element is not removed:

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 

firing Validation rules under One way binding Mode


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.)



Validation for Multiple Textboxes



I have created a table with 50 textboxes , i would like to have a custom validator which validates all the textboxes with the same validation rule  in the table and displays an error message in the label. Please help me on this issue.

Thanks in Advance

problems with trace.writeline not writing output messages on multiple instance/thread service



I've come across something strange and can't quite figure out what could be going wrong. I have a windows service which processes queue items in a threadpool (default 5 threads).

So, during testing, i "debug, start new instance" and spin up about 4-5 instances of the service, and on average there is about 25 threads going at same time.

My trace code:
Trace.WriteLineIf(traceOutput.TraceVerbose, string.Format("processing Item for {0}", item.id));


this seems to work for a while and writes the trace code to the output window, but after a while, the trace output just stops being output to the window.. has anyone else experienced this before or could know what might be going wrong?




Cannot get recommendations after querying an association rules model for multiple customers

To carry out this data mining task, I am using the Data Mining(DM) add-in of Excel 2007, 
where one has to make use of SQL Analysis Server in order to utilize the add-in.
Basically, I have a three-column dataset: CustomerID,Product,Transaction. These are the steps I am following:
1. Build an Association Rules(AR) Model.
2. Query the AR Model with new data and obtain a recommended product.
Right now, if I supply an input of Products "A","B","C" for "Customer1" I get the recommendation e.g. product "D".
This is the DMX query I am using:
PredictAssociation([Associate ProductNo].[ProductNo_Table],INCLUDE_STATISTICS,5) AS [Output 1]  
[Associate ItemNo]
{@InputRowset } APPEND ( { @InputRowset1 } RELATE [SessionNo] TO [SessionNo] ) AS [ProductNo_Table] AS
InputRowset = Microsoft.SqlServer.DataMining.Office.Excel.ExcelDataReader
InputRowset1 = Microsoft.SqlServer.Data

Multiple database support with Entity Framework

One of the features introduced in Entity Framework is being database independent. Which mean each database provider can support Entity Framework by implementing its provider.

This feature allows you build applications independent from the underplaying database provider. In this post I'm going to show how to build an application that support multiple databases using same conceptual model made by Entity Framework.

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

Upload Multiple File using JQuery in asp.net

In this article I have explained how to upload multiple files using file upload control. I have used jQuery plugin for uploading multiple files.

I have also explained how to check for file type, file maximum size limit using jQuery & also using server side validation code.
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