public object PROJECT_ACTUAL_START_DATE { get; set; }
[UIHint("Date")]
[DisplayName("Actual End Date-التاريخ الفعلي للانتهاء ")]
public object PROJECT_ACTUAL_END_DATE { get; set; }
}
In table PROJECT_INITIATIVE I have “planned start date” and “planned end date”, I have to make sure that the planned end date is greater that the planned start date.
As mentioned above I wrote the following code for the validation
Hi Amin.Mirzapour, this is the Dynamic Data forum which is a framework that sits on WebForms is uses templates ans scaffolding to give you a RAD development experience and one of the things it does is display errors in a validation list at the top of all
pages when editing.
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
Since value is nullable,I think you can use value.HasValue to check whether it's really having a real value of DateTime instead of checking whether it belongs to null or not。
As for customizing checking……If you are using LINQ-TO-SQL,you can have a look at this(Point is that you should use DynamicValidator)
How can I add dynamic validator to the previous code?
I don't think it a good idea to dynamically bind a DynamicValidator to the Calendar,maybe you can just specify the control into the aspx and assign the ControlToValidate property to deal with the problem……
I don't think it a good idea to dynamically bind a DynamicValidator to the Calendar,maybe you can just specify the control into the aspx and assign the ControlToValidate property to deal with the problem……
Hi,
unfortunately I'm an Oracle developer, and this is a new and very complicated technology for me :(
1. how can I specify the control?
2. which aspx ?
3. how and where I assign the controlTovalidate property?
AlAnoud
0 Points
7 Posts
Date Validation
Apr 05, 2012 09:27 AM|LINK
Hi all,
The following is a part of a class that I have created for manual scaffolding
[ScaffoldTable(true)]
[MetadataType(typeof(PROJECT_INITIATIVEMetaData))]
[DisplayName("Projects/Initiatives - المبادرات أو المشاريع")]
public partial class PROJECT_INITIATIVE
{ //planned end date must be greated than planned start date
partial void OnPROJECT_PLANNED_END_DATEChanging(Nullable<global::System.DateTime> value)
{
if (value != null && value < Convert.ToDateTime(this.PROJECT_PLANNED_START_DATE))
{
throw new ValidationException("Planned end date must be greated than planned start date.");
}
}
//***************************************************************************
}
public class PROJECT_INITIATIVEMetaData
{
[ScaffoldColumn(false)]
public object PROJECT_ID { get; set; }
[DisplayName("Project Code- رمز المشروع")]
public object PROJECT_CODE { get; set; }
[DisplayName("أسم المشروع")]
public object PROJECT_DESC_ARB{ get; set; }
// [Display(Name = " Project Name", Order = 3)]
[DisplayName("Project Name")]
public object PROJECT_DESC_ENG { get; set; }
[DisplayName("خطة الإنطلاق")]
public object PROJECT_BASELINE_ARB { get; set; }
[DisplayName("Project Baseline")]
public object PROJECT_BASELINE_ENG { get; set; }
[UIHint("Date")]
[DisplayName("Planned Start Date-التاريخ المتوقع للبدء")]
public object PROJECT_PLANNED_START_DATE { get; set; }
[UIHint("Date")]
[DisplayName("Planned End Date-التاريخ المتوقع للانتهاء ")]
public object PROJECT_PLANNED_END_DATE { get; set; }
[UIHint("Date")]
[DisplayName("Actual Start Date-التاريخ الفعلي للبدء")]
public object PROJECT_ACTUAL_START_DATE { get; set; }
[UIHint("Date")]
[DisplayName("Actual End Date-التاريخ الفعلي للانتهاء ")]
public object PROJECT_ACTUAL_END_DATE { get; set; }
}
In table PROJECT_INITIATIVE I have “planned start date” and “planned end date”, I have to make sure that the planned end date is greater that the planned start date.
As mentioned above I wrote the following code for the validation
partial void OnPROJECT_PLANNED_END_DATEChanging(Nullable<global::System.DateTime> value)
{
if (value != null && value < Convert.ToDateTime(this.PROJECT_PLANNED_START_DATE))
{
throw new ValidationException("Planned end date must be greated than planned start date.");
}
}
How can I display the error in the list validation errors and avoid getting “ValidationExceptionwas unhandled by user code" error
sjnaughton
All-Star
27391 Points
5485 Posts
MVP
Re: Date Validation
Apr 06, 2012 11:29 AM|LINK
Is this Entity Framework or Linq to SQL?
Always seeking an elegant solution.
Amin.Mirzapo...
Member
546 Points
98 Posts
Re: Date Validation
Apr 06, 2012 11:36 AM|LINK
Would you please give more explaination, you said:
How can I display the error in the list validation errors and avoid getting “ValidationExceptionwas unhandled by user code" error
As you threw an specific exception, naturally you'll get the mentioned exception, what do you mean by " display the error in the list "?
sjnaughton
All-Star
27391 Points
5485 Posts
MVP
Re: Date Validation
Apr 06, 2012 11:38 AM|LINK
Hi Amin.Mirzapour, this is the Dynamic Data forum which is a framework that sits on WebForms is uses templates ans scaffolding to give you a RAD development experience and one of the things it does is display errors in a validation list at the top of all pages when editing.
Always seeking an elegant solution.
Amin.Mirzapo...
Member
546 Points
98 Posts
Re: Date Validation
Apr 06, 2012 12:53 PM|LINK
Thanks stive.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Date Validation
Apr 07, 2012 01:35 AM|LINK
Hello:)
Since value is nullable,I think you can use value.HasValue to check whether it's really having a real value of DateTime instead of checking whether it belongs to null or not。
As for customizing checking……If you are using LINQ-TO-SQL,you can have a look at this(Point is that you should use DynamicValidator)
http://msdn.microsoft.com/en-us/library/cc488527.aspx
AlAnoud
0 Points
7 Posts
Re: Date Validation
Apr 09, 2012 06:50 AM|LINK
It is Entity Framework
AlAnoud
0 Points
7 Posts
Re: Date Validation
Apr 09, 2012 07:20 AM|LINK
Hi all,
I think the problem is in Date_Edit.ascx
<%
@ Control Language="C#" CodeBehind="Date_Edit.ascx.cs" Inherits="GSDP_MES.DynamicData.FieldTemplates.Date_EditField"
%>
<
asp:Calendar ID="DateCalendar" runat="server"></asp:Calendar
>
How can I add dynamic validator to the previous code?
Please recommend
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Date Validation
Apr 09, 2012 07:31 AM|LINK
Hello again:)
I don't think it a good idea to dynamically bind a DynamicValidator to the Calendar,maybe you can just specify the control into the aspx and assign the ControlToValidate property to deal with the problem……
AlAnoud
0 Points
7 Posts
Re: Date Validation
Apr 09, 2012 07:44 AM|LINK
Hi,
unfortunately I'm an Oracle developer, and this is a new and very complicated technology for me :(
1. how can I specify the control?
2. which aspx ?
3. how and where I assign the controlTovalidate property?
Thanks,