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

I am using Asp.Net with C#.
I have 4 dropdownlists 1st and 3 Dropdownlist contains Hours as List Items starting from 00-23(hours), 2nd and 4th one contains Minutes as ListItems starting from 00 to 59(minutes). Now how do i compare hours dropdownlist values in order to find time difference.

Is there any Validation control to validate it at client side?

Can we do Compare Validation of Two DropDownList filled with Time Value?

if anybody know answer for this please reply it to me.

Thanks
Posted
Updated 16-Feb-11 3:21am
v2
Comments
Sandeep Mewara 16-Feb-11 9:55am    
Winforms or ASp.NET?

Client side date difference with javascript:

<script type="text/javascript">

var date1 = new Date(2011, 1, 16);  //Months are 0-11 in javascript
var date2 = new Date(2011, 1, 1);

//get 1 day in milliseconds
var one_day = 1000*60*60*24;

document.write(Math.ceil((date1.getTime() - date2.getTime()) / one_day);

</script>
 
Share this answer
 
Use custom validation. Example of custom validation control bellow:


XML
<asp:Label id=lblOutput runat="server"
           Text="Enter an even number:"
           Font-Name="Verdana"
           Font-Size="10pt">


<asp:CustomValidator id="CustomValidator1"
           ControlToValidate="Text1"
           OnServerValidate="ServerValidation"
           Display="Static"
           ErrorMessage="Not an even number!"
           ForeColor="green"
           Font-Name="verdana"
           Font-Size="10pt"
           runat="server">

      <asp:Button id="Button1"
           Text="Validate"
           OnClick="ValidateBtn_OnClick"
           runat="server"/>



C#
void ValidateBtn_OnClick(object sender, EventArgs e)
     {
        if (Page.IsValid)
        {
           lblOutput.Text = "Page is valid.";
        }
        else
        {
           lblOutput.Text = "Page is not valid!";
        }
     }
     void ServerValidation (object source, ServerValidateEventArgs arguments)
     {
        int i = int.Parse(arguments.Value);
        arguments.IsValid = ((i%2) == 0);
     }
 
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