Click here to Skip to main content
15,885,899 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello

i have 2 datetime picker ie:

From Date : datetime picker1
To Date : datetime picker2
and one search button in my form.

now my question is how to show the error notification on each datetime picker.

Example if any user click on search button with out selecting any datapicker i.e From date or To date..then message should come like "please select date first!!

another :
From Date :7-4-2011 To date: 7-4-2009 then error should come saying "you have enter wrong format of date"

plz help me out!!
Posted

for your second querry You can set minimum date as current date so the wrong format can't be inserted.

And for the first one you can use valuechanged property ex if value is changed only then the search starts.
 
Share this answer
 
Comments
rbnsubedi 4-Jul-11 13:58pm    
Code please if u like to help me out!!
theanil 4-Jul-11 14:05pm    
i have helped you by giving idea but its your job to code it. i dont have ready code...
rbnsubedi 4-Jul-11 14:17pm    
i have tried ...
C#
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
if (dateTimePicker1.Value > dateTimePicker2.Value)
   {
MessageBox.Show("you have enter wrong format of date"");
 
Share this answer
 
Comments
theanil 4-Jul-11 14:28pm    
it might not work, the reason is as you select date from picker11 the method is called and the picker2 value will be default date...
theanil 4-Jul-11 14:30pm    
better way is to write the particular code in a private method and call the method as your search button is clicked
If you have complex logic to implement you could
write a custom validator inheriting ComapreValidator and write all the validation logic you want in the validation method.

C#
public class V1 : CompareValidator
{
    protected override bool EvaluateIsValid()
    {
        //validation logic
        //......
        this.ErrorMessage = "message";//kind of validation error
    }

    //needed only if you want to validate controls that, by default cannot
    //be  validated, a calendar control (for example)
    protected override bool ControlPropertiesValid()
    {
        return true;
    }

}


to mantain simple the code, uncheke "Enable client validation" or override the property setting false by default, so that javascript validation in turned off.
If you enable client validation you have also to implement javascript logic...

Hope this help.
 
Share this answer
 
The datetime object allows comparison, you can just do if (picker2.Value < picker1.Value) then xxx. If you can't write that, then you should read a book, not ask random strangers to give you code to copy and paste because you refuse to learn the basics.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900