Click here to Skip to main content
15,911,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Date of birth TExtbox1(Calendar Image)

Wedding date TExtbox2(calendar Image)

Insert (Button)

when i run and click the insert button i want to show the message "Date of birth or wedding date is not selected";

for that i write the validation Code has follows;

if(DOB.SelectedDateValue.ToString()=="" && Wedding.SelectedDateValue.ToString()== "")
{
LblErr.Text = "Date of birth or wedding date is not selected";
return;
}



suppose user did not select the date of birth and select the wedding date and click the insert button.

the message does not shows, Date of birth or wedding date is not selected.

it is inserted the record.

from my above validation code what is the problem

please correct my code.
Posted

Instead of Img Button.. Check is textbox is empty or not..

if((TextBox1.Text==string.Empty) || TextBox2.Text==string.Empty))
 
Share this answer
 
v3
Comments
Suvabrata Roy 27-Dec-12 4:51am    
If you use && then the message will show only when both are empty
but requirement is any one if empty.
SQL
if(DOB.SelectedDateValue.ToString()=="" || Wedding.SelectedDateValue.ToString()== "")
{
LblErr.Text = "Date of birth or wedding date is not selected";
return;
}
 
Share this answer
 
Initially what do you have in this control?
DOB.ToString()



You can always compare what is in the control currently with the current computer date.

So if the
C#
DOB.ToString()==ComputerDate.string()
            {
             //then it means person haven't selected the wedding date
             //throw you error message
            }

This is just the logic on how to check if the control is clicked by checking change.
 
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