protected void txt_to_date_TextChanged(object sender, EventArgs e) { IFormatProvider theCultureInfo = new System.Globalization.CultureInfo("en-GB", true); DateTime from_date = DateTime.ParseExact(txt_from_date.Text, "dd/MM/yyyy", theCultureInfo); DateTime to = DateTime.ParseExact(txt_to_date.Text, "dd/MM/yyyy", theCultureInfo); int result = DateTime.Compare(to, from_date); if (result < 0) { txt_to_date.Text = ""; txt_to_date.Focus(); lbl_msg.Visible = true; lbl_msg.ForeColor = System.Drawing.Color.Red; lbl_msg.Text = "To date is not Less than your From Date"; txt_total_days.Text = ""; } else if (result == 0) { txt_total_days.Text = "1"; Panel1.Visible = true; } else { Panel2.Visible = false; Panel1.Visible = false; txt_total_days.Text = ((to - from_date).TotalDays + 1).ToString(); } } the ASPX code like : <asp:ScriptManager ID="s1" runat="server"></asp:ScriptManager> <asp:UpdatePanel ID="up1" runat="server"> <ContentTemplate> <table border="1" width="100%"> <tr> <td align="center" colspan="2"> <asp:Label ID="Label1" runat="server" Text="Online Leave Application" Font-Size="Large" ForeColor="Black" Font-Bold="True"></asp:Label> </td> </tr> <tr> <td align="left"> <asp:Label ID="Label2" runat="server" Text="Date" Font-Size="Medium" ForeColor="Black"></asp:Label> </td> <td align="left"> <asp:TextBox ID="txt_date" runat="server" Columns="20" Font-Size="Medium" Enabled="False"></asp:TextBox> </td> </tr> <tr> <td align="left"> <asp:Label ID="Label5" runat="server" Text="From Date" Font-Size="Medium" ForeColor="Black"></asp:Label> </td> <td align="left"> <asp:TextBox ID="txt_from_date" runat="server" Columns="20" ValidationGroup="temp" Font-Size="Medium" Enabled="False"></asp:TextBox> <asp:ImageButton ID="ImageButton1" runat="server" Height="25px" ImageUrl="~/Images1/calendar.jpg" Width="30px" ValidationGroup="temp" onclick="ImageButton1_Click1"/> <ajax:CalendarExtender ID="CalendarExtender1" runat="server" PopupButtonID="ImageButton1" TargetControlID="txt_from_date" OnClientDateSelectionChanged="chkdate" Format="dd/MM/yyyy"> </ajax:CalendarExtender> </td> </tr> <tr> <td align="left"> <asp:Label ID="Label6" runat="server" Text="To Date" Font-Size="Medium" ForeColor="Black"></asp:Label> </td> <td align="left"> <asp:TextBox ID="txt_to_date" runat="server" Columns="20" ValidationGroup="temp1" Font-Size="Medium" Enabled="False" EnableTheming="True" ontextchanged="txt_to_date_TextChanged" AutoPostBack="True"></asp:TextBox> <asp:ImageButton ID="ImageButton2" runat="server" Height="25px" ImageUrl="~/Images1/calendar.jpg" Width="30px" ValidationGroup="temp1" onclick="ImageButton2_Click" /> <ajax:CalendarExtender ID="CalendarExtender2" runat="server" PopupButtonID="ImageButton2" TargetControlID="txt_to_date" OnClientDateSelectionChanged="chkdate" Format="dd/MM/yyyy"> </ajax:CalendarExtender> <asp:CustomValidator ID="scdt1" runat="server" OnServerValidate="chkdate1" ErrorMessage="To date not less than From date" ControlToValidate="txt_from_date"></asp:CustomValidator> </td> </tr> <tr> <td align="left"> <asp:Label ID="Label9" runat="server" Text="Total Leave(s) Day(s)" Font-Size="Medium" ForeColor="Black"></asp:Label> </td> <td align="left"> <asp:TextBox ID="txt_total_days" runat="server" Text="0" Enabled="false" Font-Size="Medium" ForeColor="Black"></asp:TextBox> </td> </tr> <tr> <td align="center" colspan="2"> <asp:Panel ID="Panel1" runat="server" Visible="false"> <asp:RadioButton ID="rd_full" runat="server" Text="Full Day Leave" GroupName="a" Checked="true" AutoPostBack="True" Font-Size="Medium" ForeColor="Black" oncheckedchanged="rd_full_CheckedChanged" /> <asp:RadioButton ID="rd_half" runat="server" Text="Half Day Leave" GroupName="a" AutoPostBack="True" Font-Size="Medium" ForeColor="Black" oncheckedchanged="rd_half_CheckedChanged" /> </asp:Panel> </td> </tr> <tr> <td align="center" colspan="2"> <asp:Panel ID="Panel2" runat="server" Visible="false"> <asp:RadioButton ID="rd_first_half" runat="server" Text="First Half" GroupName="b" Checked="true" Font-Size="Medium" ForeColor="Black" oncheckedchanged="rd_first_half_CheckedChanged" /> <asp:RadioButton ID="rd_second_half" runat="server" Text="Second Half" GroupName="b" Font-Size="Medium" ForeColor="Black" /> </asp:Panel> </td> </tr> <tr> <td align="left"> <asp:Label ID="Label8" runat="server" Text="Enter Reason" Font-Size="Medium" ForeColor="Black"></asp:Label> </td> <td align="left"> <asp:TextBox ID="txt_reason" runat="server" TextMode="MultiLine" Font-Size="Large" ForeColor="Black" Height="150px" Width="450px" ></asp:TextBox> </td> </tr> <tr> <td align="left"> <asp:Label ID="Label7" runat="server" Text="Report To Whom" Font-Size="Medium" ForeColor="Black"></asp:Label> </td> <td align="left"> <asp:TextBox ID="TextBox1" runat="server" Columns="45" Font-Size="Medium" ForeColor="Black" Enabled="False"></asp:TextBox> </td> </tr> <tr> <td align="center" colspan="2"> <asp:Button ID="Button1" runat="server" Text="Submit" Font-Size="Large" ForeColor="Black" Width="30%" OnClientClick="return validate()" onclick="Button1_Click1" /> </td> </tr> <tr> <td align="center" colspan="2"> <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="up1"> <ProgressTemplate> <div align="center" style="color: #000000"> <img src="images/progress.gif" align="middle" height="20" /> Please Wait ... </div> </ProgressTemplate> </asp:UpdateProgress> </td> </tr> <tr> <td align="center" colspan="2"> <asp:Label ID="lbl_msg" runat="server" Font-Size="Medium" ForeColor="Green" Visible="False"></asp:Label> </td> </tr> </table> </ContentTemplate> </asp:UpdatePanel>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)