Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
740
Validating UltraDateTimeEditor Field
posted

Hi there,

I want to validate Date of Birth field which uses a UltraDateTimeEditor with following conditions:

1. If the user selects a Date of Birth greater than TODAY's date, shoud give an error "The date of birth must be before today"

2. If the user selects a date, greater than 2 months before  e.g. Today  - 22-10-2008 :Selected Date - 22-07-2008, should give a warning : "Warning : xxxxx!!" 3. For the both of the condition falis, default the UltraDateTimeEditor text in to "00/00/0000" format and focusI would like to know whether I can do both these validations using the Validation Settings in the ultravalidator or do I have to do it in the coding 

I have written the following coding, but it doesn’t give the outputs that I needed. 

=================================================================================================

 // For the 1st Conditionthis.udtDOB.Name = "udtDOB";

this.udtDOB.NullText = "00/00/0000";

this.udtDOB.Size = new System.Drawing.Size(95, 21);

this.udtDOB.TabIndex = 24;

ultraToolTipInfo2.ToolTipText = "Please enter date of birth";

this.ultraToolTipManager1.SetUltraToolTip(this.udtDOB, ultraToolTipInfo2);

this.ultraValidator1.GetValidationSettings(this.udtDOB).Condition = new Infragistics.Win.OperatorCondition(Infragistics.Win.ConditionOperator.GreaterThan, System.DateTime.Today, true, typeof(System.DateTime));

this.ultraValidator1.GetValidationSettings(this.udtDOB).DataType = typeof(System.DateTime);

this.ultraValidator1.GetValidationSettings(this.udtDOB).IsRequired = true;

this.ultraValidator1.GetValidationSettings(this.udtDOB).NotificationSettings.Caption = "Validation Faild";

this.ultraValidator1.GetValidationSettings(this.udtDOB).NotificationSettings.Text = "The date of birth must be before today";

this.ultraValidator1.GetValidationSettings(this.udtDOB).ValidationPropertyName = "Value";

this.ultraValidator1.GetValidationSettings(this.udtDOB).ValidationTrigger = Infragistics.Win.Misc.ValidationTrigger.OnValidating;

this.udtDOB.Value = null;

=================================================================================================

// For the 2nd Condition

        private void udtDOB_ValueChanged(object sender, EventArgs e)        {                  if (udtDOB.Value != null)           {                int monthDiff = DateTime.Today.Month - Convert.ToDateTime(udtDOB.Value).Month;                 if (monthDiff > 2)                {                    MessageBox.Show(this, "Warning xxxxxxxxxxx", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);                    udtDOB.Value = null;                }            }        } 

=================================================================================================

Urgent Help needed ! Thanks in Advance!

NW 

 

Parents Reply Children
No Data