How to Compare Two Calender Extender In Asp.Net

How to Compare Two Calender Extender In Asp.Net

In this tutorial we will learn How to Compare Two Calender Extender In Asp.Net. Here we compare two dates in using two textbox controls and two ajax calender extender controls. You can use calender controls instead of ajax calender extender controls but date formats must be same for both textbox’s date values.


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html>

<html xmlns="">
<head runat="server">
<title>How to Compare Two Calender Extender In Asp.Net</title>
<style type="text/css">
 width: 980px;
 margin: 0px auto;
 text-align: center;
 padding-top: 50px;
 font-size: 20px;
<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>
<h2>How to Compare Two Calender Extender In Asp.Net</h2>
<br /><br /><br /><br />

Start Date: <asp:TextBox ID="startdate" runat="server"></asp:TextBox>
End Date: <asp:TextBox ID="enddate" OnTextChanged="enddate_TextChanged" AutoPostBack="true" runat="server"></asp:TextBox>

<asp:CalendarExtender ID="CalendarExtender1" TargetControlID="startdate" runat="server"></asp:CalendarExtender>
<asp:CalendarExtender ID="CalendarExtender2" TargetControlID="enddate" runat="server"></asp:CalendarExtender>

<br /><br />
<br /><br />
All rights reserved by <a href=""></a> |
     Hosting partner <a href="" target="_blank">Grootstech</a>  


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)

    protected void enddate_TextChanged(object sender, EventArgs e)
        DateTime a = DateTime.Parse(startdate.Text);
        DateTime b = DateTime.Parse(enddate.Text);

        if (a > b)
        Response.Write("<script>alert('End Date Should be Less then Start Date');</script>");