Click here to Skip to main content
14,698,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

i have a textbox which accepts hours. The max length is 4. Only numeric and decimal values can be entered in the textbox so when the user enters values like


on click of ok button an alert should be displayed.

previously i was using this condition
if(plannedHours == "0")

// display an alert message.

But now since the user is allowed to enter decimal values also, the above combinations of zero's with or without decimal points is not displaying an alert message when user clicks on ok button.

so how can i give a condition so that it satisfies all the possible combinations of zero's with and without decimal also?

please provide me a solution in C#.

1 solution

Try this code
if(Convert.ToDouble(plannedHours) == 0)

// display an alert message.
george4986 6-Mar-14 0:21am
+5v ;-)
Member 10593922 6-Mar-14 0:32am
Thanks for the reply... but m still facing the same problem. can u suggest any other solution?
R-a-v-i-k-u-m-a-r 6-Mar-14 0:47am
Tested on my machine it works perfectly. are you getting any error?
Member 10593922 6-Mar-14 0:59am
no am not getting any error. but its not displaying any alert message. am using this condition in one more place as mentioned below
if (equipmentId != string.Empty && operationDesc.Trim() != string.Empty && ddlComponentCode.SelectedValue != null && plannedHours != string.Empty && Convert.ToDecimal(plannedHours) != 0)
if (String.IsNullOrWhiteSpace(txtPlannedHours.Text))
alertMessage = this.FindResource("createWorkOrder_Alert_PlannedTime").ToString();
AlertWindow oAlertWindow = new AlertWindow(MessageType.Alert, alertMessage);
oAlertWindow.Owner = GlobalVariablesBO.ApplicationWindow;
txtPlannedHours.Text = string.Empty;
}//do something
{ if (projectId == string.Empty || (equipmentId == string.Empty) || (operationDesc.Trim() == string.Empty) ||
(ddlComponentCode.SelectedValue == null) || (plannedHours == string.Empty))
alertMessage = this.FindResource("createWorkOrder_Validation").ToString();
else if (Convert.ToDecimal(plannedHours) == 0)
{// display alert
Member 10593922 6-Mar-14 1:22am
so should i pass convert to double in all the places where am using planned hour field?
R-a-v-i-k-u-m-a-r 6-Mar-14 1:28am
Use break points whether it hits the 2 else blocks and check the values of fields.

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