Hi sonasri,
Refer the below sample.
HTML
<div>
From Time:<asp:TextBox ID="txtFrom" runat="server" />
<br />
To Time:<asp:TextBox ID="txtTo" runat="server" />
<br />
<asp:Button Text="Check Time" runat="server" OnClick="Check" />
</div>
C#
protected void Check(object sender, EventArgs e)
{
TimeSpan fromTime = Convert.ToDateTime(txtFrom.Text.Trim()).TimeOfDay;
TimeSpan toTime = Convert.ToDateTime(txtTo.Text.Trim()).TimeOfDay;
if (fromTime < toTime)
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert('FromTime should be greater than the ToTime')", true);
}
else
{
// do your task.
}
}
VB.Net
Protected Sub Check(sender As Object, e As EventArgs)
Dim fromTime As TimeSpan = Convert.ToDateTime(txtFrom.Text.Trim()).TimeOfDay
Dim toTime As TimeSpan = Convert.ToDateTime(txtTo.Text.Trim()).TimeOfDay
If fromTime < toTime Then
ClientScript.RegisterClientScriptBlock(Me.[GetType](), "alert", "alert('FromTime should be greater than the ToTime')", True)
' do your task.
Else
End If
End Sub