Tuesday, November 24, 2015

What is Ajax

Ajax stands for Asynchronous JavaScript And XML. Ajax is not a technology or a product , it is just a way to refer a set of existing standards used together for developing faster interfaces, improve the user experience and better response times. Ajax support for the most popular web browsers, which includes Microsoft Internet Explorer, Mozilla Firefox, Google Chrome etc. The public use of Ajax can be found worldwide such as Google Maps, Google Suggest, Live.com etc.
ajax
Ajax introduces a new approach to WebPages that update the portion of a the page by a techniques called Partial-page rendering. Partial-page rendering eliminate the traditional way of doing a full postback (full page refresh) to the web server and updates only the necessary portion of the web page. That is, only the necessary data is transferred back and forth between the client and the web server . Using this techniques you can cut down on the network load , bandwidth usage and moreover the web page is not locked during the server processing. It helps in creating faster, better, dynamic and interactive web applications.
Ajax is a combination of existing technologies such as XMLHttpRequest Object, JavaScript, DHTML, DOM and XML. XMLHttpRequest object is responsible for the partial updates of web pages by using JavaScript to make requests to the web server and process the response. XMLHTTP is a protocol that is designed to package data as XML and send it via the network to the web server.

How to ASP.NET Ajax

ASP.NET Ajax extension is a part of ASP.NET that makes Ajax functionalities possible and effective. ASP.NET Ajax, formerly known as Atlas, is an extension of ASP.NET 2.0. Ajax extension has developed for both client side and server side. The core part of the Ajax extension client library is the networking layer that manages the complexity of making asynchronous calls over XMLHttpRequest.
XMLHttpRequest is the core of making AJAX web applications. It acts as a communication layer between the server and the client. XMLHttpRequest object is responsible for the partial updates of web pages by using JavaScript to make requests to the web server and process the response without posting the full web page back to the web server. XMLHTTP is a protocol that is designed to package data as XML and send it via the network to the web server. XmlHttpRequest object is today fully supported by the majority of Web browsers.
The most frequently used ASP.NET Ajax server controls are ScriptManager, UpdatePanel , UpdateProgress and Timer. With the help of ScriptManager Control and UpdatePanel control, ASP.NET Ajax can refresh selected parts of the web page instead of refreshing the whole page with a postback. UpdateProgress provides status information for the progress of the download occurring in the UpdatePanel and the Timer control enables you to perform postbacks at a specified interval.

ASP.NET Ajax ServerControls

ASP.NET Ajax server controls consist of server and client code that integrate to produce rich client behavior. The following list describes the most frequently used Ajax server controls
  ScriptManager Control
  UpdatePanel Control
  UpdateProgress Control
Timer Control

ScriptManager Control :
The ScriptManager control is the essential core for the AJAX Extensions that makess ASP.NET AJAX possible by managing the JavaScript for you behind the scenes. There are a number of client script libraries available to ASP.NET developers, and when a ScriptManager is used, only the relevant ones are downloaded to the client. Moreover ScriptManager control supports the UpdatePanel controls to handles the asynchronous postbacks and refreshes only the regions of the page that have to be updated (partial-page rendering). The ScriptManager control will be visible in design view but will not be visible when the web site is run.
UpdatePanel Control :
UpdatePanel control is used to visually design the part of the page that is used in partial-page rendering. Placing controls inside an UpdatePanel control enables you to refresh selected parts of the webpage instead of refreshing the whole page with a postback to the webserver. When the UpdatePanel control performs an asynchronous post, it adds a custom HTTP header. There is no limit to the number of UpdatePanel controls that can be on a page, and they can be nested. Each UpdatePanel is updated individually and asynchronously, without affecting one another or anything else on the page.
UpdateProgress Control :
UpdateProgress control shows the status information for the progress of the download occurring in the UpdatePanel. The page can contain multiple UpdateProgress controls. Each one can be associated with a different UpdatePanel control. Alternatively, you can use one UpdateProgress control and associate it with all the UpdatePanel controls on the page.
Timer Control :
The Timer control enables you to perform postbacks at a specified interval. It can be used to trigger automatic updates to an area of the page that is wrapped with an UpdatePanel.

First Asp.Net Ajax Program

Ajax introduces a new approach to WebPages that update the portion of a webpage by a techniques called Partial-page rendering. In the following example you can learn the difference between How a Partial-page rendering and a traditional way of page update works in a same web page.

The ScriptManager control is the essential core for the ASP.NET AJAX Extensions. We have to use a ScriptManager Control in just about every Ajax application. In the following example we placed a ScriptManager control , one UpdatePanel Control, two Buttons named Ajax-Button and Non-Ajax-Button and two label controls in the form.

The first Button (Ajax-Button) is placed inside the UpdatePanel control area and the second Button (Non-Ajax-Button) placed outside the UpdatePanel control area. When you run this application and clicked first button (Ajax-Button), then you can see the first label control only updated the current server time. When you clicked on second Button (Non-Ajax-Button) you can see both label control will update the current server time. This is happening because the first Button(Ajax-Button) and label control we placed inside the UpdatePanel Control area and it behaves like Partial-page rendering. That means it will update only the portion of the webpage (between UpdatePanel Control area) while clicking first Button. When you clicked on the second Button (Non-Ajax-Button) you can see both labels updated with current server time ,because second Button (Non-Ajax Button) is placed outside the UpdatePanel area and it behaves like ordinary web application and updated both labels. That means a full page refresh or full postback to the web server is happening while clicking second Button.

Default.aspx

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <!--  Ajax button code start -->
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
            <asp:Button ID="Button1" runat="server" Text="Ajax - Button" onclick="Button1_Click" />
        </ContentTemplate>
        </asp:UpdatePanel>
        <!--  Ajax button code end -->
        <br /><br />
        <!--  Non - Ajax button code start -->
        <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
        <asp:Button ID="Button2" runat="server" Text="Non - Ajax - Button" onclick="Button2_Click" />
        <!--  Non - Ajax button code end -->
    </div>
    </form>
</body>
</html>

ASP.NET Ajax UpdateProgress

UpdateProgress control shows the status information for the progress of the download occurring during the partial-page rendering in the UpdatePanel. The page can contain multiple UpdateProgress controls. Each one can be associated with a different UpdatePanel control. Alternatively, you can use one UpdateProgress control and associate it with all the UpdatePanel controls on the page.

ajax
You can place UpdateProgress control either inside or outside the UpdatePanel controls. The following Asp.Net program shows how to an UpdateProgress control waits for completion of the task and during this waiting time it shows a .gif file as waiting message.

Default.aspx

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate>
<img alt="ajax-progress" src="http://asp.net-informations.com/ajax/img/ajax-progress.gif"></img>
</ProgressTemplate>
  </asp:UpdateProgress>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
  <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
  <br />
  <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>

ASP.NET Ajax Timer

The Timer control can work as a trigger to an area of the page that is wrapped with an UpdatePanel Control. It performs postbacks at defined intervals. The Interval property is defined in milliseconds, so that setting the Interval property to 5000 milliseconds will refresh the UpdatePanel control every 5 seconds.

The following asp.net program placed a Timer and label controls inside the UpdatePanel control area and one label control outside the UpdatePanel control area. When you run this program first label shows the current server time as page loaded time. After five seconds the second Label inside the UpdatePanel control shows the current server time. After that each five seconds you can see the second label only updating the current server time , because partal page updating is happening at defined intervals.

Default.aspx

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br /><br />
<asp:ScriptManager ID="ScriptManager1" runat="server"/>
<asp:Timer ID="Timer1" runat="server" interval="5000" ontick="Timer1_Tick" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger controlid="Timer1" eventname="Tick" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>

ASP.NET Ajax Toolkit

ASP.NET AJAX Control Toolkit is an open-source project fromCodePlex and built on the top of the Microsoft ASP.NET AJAX framework. These controls are designed using concepts that are familiar to ASP.NET Web Forms application developers. Using the Ajax Control Toolkit, you can build Ajax-enabled ASP.NET Web Forms applications by drag and drop Toolkit controls from the Visual Studio Toolbox onto an ASP.NET Web Forms page.
How to Ajax Control Toolkit ?
The first step is to download the compatible version of the Ajax Control Toolkit. You can download the latest version of the Ajax Control Toolkit from CodePlex.
After downloading the Ajax Control Toolkit compressed file, right-click the file and select the Extract All menu option.
Launch Visual Studio and create a new ASP.NET Web Forms project or website. Open Default.aspx in the Visual Studio editor.
Create a new Toolbox tab by right-clicking the Toolbox and selecting Add Tab . Name the new tab Ajax Control Toolkit.
Right-click beneath the new tab and select the menu optionChoose Items... Click the Browse button and browse to the folder where you extracted the Ajax Control Toolkit. Pick theAjaxControlToolkit.dll and click the OK button to close the Choose Toolbox Items dialog.
For more information about how to integrate Ajax Toolkit with your Visual Studio : http://www.asp.net/ajaxlibr

Ajax Accordion from database

ASP.NET AJAX Control Toolkit is a joint effort between Microsoft and the ASP.NET AJAX community that provides a powerful infrastructure to write reusable, customizable and extensible ASP.NET AJAX extenders and controls. An Accordion Control contains several Accordion Panes and displays a single AccordionPane at a time.

accordion-database
The following program shows how to fill the Accordion Panes dynamically from database values.

vb.net
  Dim pane1 As New AjaxControlToolkit.AccordionPane()
  pane1.ID = "pane" & i
  pane1.HeaderContainer.Controls.Add(New LiteralControl(ds.Tables(0).Rows(i).ItemArray(0).ToString()))
  pane1.ContentContainer.Controls.Add(New LiteralControl(ds.Tables(0).Rows(i).ItemArray(1).ToString()))
  Accordion1.Panes.Add(pane1)

C#
  AjaxControlToolkit.AccordionPane pane1 = new AjaxControlToolkit.AccordionPane();
  pane1.ID = "pane" + i;
  pane1.HeaderContainer.Controls.Add(new LiteralControl(ds.Tables[0].Rows[i].ItemArray[0].ToString()));
  pane1.ContentContainer.Controls.Add(new LiteralControl(ds.Tables[0].Rows[i].ItemArray[1].ToString()));
  Accordion1.Panes.Add(pane1);

The following Asp.Net Ajax program connect to the pubs database and displays title and notes fields from title table to Ajax Accordion Panes. To use the Ajax Control Toolkit in your Visual Studio project, you should add reference to the AjaxControlToolkit.dll in your project.

Default.aspx

 

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
.accordion {
width: 200px;
}
.accordionHeader {
border: 1px solid #2F4F4F;
color: white;
background-color: #2E4d7B;
font-family: Arial, Sans-Serif;
font-size: 12px;
font-weight: bold;
padding: 5px;
margin-top: 5px;
cursor: pointer;
}
.accordionHeaderSelected {
border: 1px solid #2F4F4F;
color: white;
background-color: #5078B3;
font-family: Arial, Sans-Serif;
font-size: 12px;
font-weight: bold;
padding: 5px;
margin-top: 5px;
cursor: pointer;
}
.accordionContent {
background-color: #D3DEEF;
border: 1px dashed #2F4F4F;
border-top: none;
padding: 5px;
padding-top: 10px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:Accordion
ID="Accordion1"
CssClass="accordion"
HeaderCssClass="accordionHeader"
HeaderSelectedCssClass="accordionHeaderSelected"
ContentCssClass="accordionContent"
runat="server">
</asp:Accordion>
</div>
</form>
</body>
</html>

ASP.NET Ajax Accordion

The Ajax Control Toolkit contains controls that you can use to build highly responsive and interactive Ajax-enabled Web applications. The Accordion Control manages your content into expandable Panes which can be clicked to make the content of that Pane visible and hiding all the other Panes.

ajax-accordion
An Accordion Control contains several Accordion Panes and displays a single AccordionPane at a time. Each AccordionPane contains both a header and content tag. We can fill each header and content tag through programmatically to Accordion Control.

vb.net
  Dim pane1 As New AjaxControlToolkit.AccordionPane()
  pane1.ID = "pane1"
  pane1.HeaderContainer.Controls.Add(New LiteralControl("Pane 1"))
  pane1.ContentContainer.Controls.Add(New LiteralControl("This is Accordion Pane No 1"))
  Accordion1.Panes.Add(pane1)

C#
  AjaxControlToolkit.AccordionPane pane1 = new AjaxControlToolkit.AccordionPane();
  pane1.ID = "pane1";
  pane1.HeaderContainer.Controls.Add(new LiteralControl("Pane 1"));
  pane1.ContentContainer.Controls.Add(new LiteralControl("This is Accordion Pane No 1"));
  Accordion1.Panes.Add(pane1);

The following Asp.Net Ajax program shows how to set up an Accordion control with 4 panes in a web application. To use the Ajax Control Toolkit in your Visual Studio project, you should add reference to the AjaxControlToolkit.dll in your project.

Default.aspx

 

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
.accordion {
width: 200px;
}
.accordionHeader {
border: 1px solid #2F4F4F;
color: white;
background-color: #2E4d7B;
font-family: Arial, Sans-Serif;
font-size: 12px;
font-weight: bold;
padding: 5px;
margin-top: 5px;
cursor: pointer;
}
.accordionHeaderSelected {
border: 1px solid #2F4F4F;
color: white;
background-color: #5078B3;
font-family: Arial, Sans-Serif;
font-size: 12px;
font-weight: bold;
padding: 5px;
margin-top: 5px;
cursor: pointer;
}
.accordionContent {
background-color: #D3DEEF;
border: 1px dashed #2F4F4F;
border-top: none;
padding: 5px;
padding-top: 10px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:Accordion
ID="Accordion1"
CssClass="accordion"
HeaderCssClass="accordionHeader"
HeaderSelectedCssClass="accordionHeaderSelected"
ContentCssClass="accordionContent"
runat="server">
</asp:Accordion>
</div>
</form>
</body>
</html>

Ajax Accordion from XML

The ASP.NET Ajax Control Toolkit contains more than 40 controls, including the Accordion , AutoComplete, CollapsiblePanel, ColorPicker, MaskedEdit, Calendar, HTML Editor Extender, and Watermark controls. The Accordion Control manages your content into expandable Panes which can be clicked to make the content of that Pane visible and hiding all the other Panes.

accordion-xml
An Accordion Control contains several Accordion Panes and displays a single AccordionPane at a time. Each AccordionPane contains both a header and content tag. The following Asp.Net Ajax program shows how to fill Accordion Panes from an XML file. The sample xml file you can download from here Accordion XML file. Download and Copy the XML file to your c:\ .

To use the Ajax Control Toolkit in your Visual Studio project, you should add reference to the AjaxControlToolkit.dll in your project.

Default.aspx

 

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
.accordion {
width: 200px;
}
.accordionHeader {
border: 1px solid #2F4F4F;
color: white;
background-color: #2E4d7B;
font-family: Arial, Sans-Serif;
font-size: 12px;
font-weight: bold;
padding: 5px;
margin-top: 5px;
cursor: pointer;
}
.accordionHeaderSelected {
border: 1px solid #2F4F4F;
color: white;
background-color: #5078B3;
font-family: Arial, Sans-Serif;
font-size: 12px;
font-weight: bold;
padding: 5px;
margin-top: 5px;
cursor: pointer;
}
.accordionContent {
background-color: #D3DEEF;
border: 1px dashed #2F4F4F;
border-top: none;
padding: 5px;
padding-top: 10px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:Accordion
ID="Accordion1"
CssClass="accordion"
HeaderCssClass="accordionHeader"
HeaderSelectedCssClass="accordionHeaderSelected"
ContentCssClass="accordionContent"
runat="server">
</asp:Accordion>
</div>
</form>
</body>
</html>

Ajax ConfirmButtonExtender

ASP.NET AJAX Control Toolkit is an open-source project built on top of the Microsoft ASP.NET AJAX framework. The Ajax Control Toolkit contains a rich set of controls that you can use to build highly responsive and interactive Ajax-enabled Web applications.

confirmationButton
The Ajax Control Toolkit contains more than 40 controls. The ConfirmButton is a simple extender that displays the confirm box with a confirmation message and OK, Cancel button also catches clicks on a button and displays a message to end user.

To use the Ajax Control Toolkit in your Visual Studio project, you should add reference to the AjaxControlToolkit.dll in your project.

Default.aspx

 

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
        <br />
        <asp:Label ID="Label2" runat="server" Text="">
        </asp:Label>
        <br /><br />
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:Button ID="btnConfirm" runat="server" Text="Show Server Time"
            OnClick="btnConfirm_Click" />
            <asp:ConfirmButtonExtender ID="ConfirmButtonExtender1" runat="server"
            TargetControlID="btnConfirm"
            ConfirmText="Dyou want to see current server time ?"
            ConfirmOnFormSubmit="false">
            </asp:ConfirmButtonExtender>
            <br /><br />
            <asp:Label ID="lblMessage" runat="server">
            </asp:Label><br />
        </ContentTemplate>
        </asp:UpdatePanel>
</div>
</form>
</body>
</html>

Ajax AsyncFileUpload Control

Ajax introduces a new approach to WebPages that update the portion of a the page by a techniques called Partial-page rendering. The Ajax Control Toolkit contains controls that you can use to build highly responsive and interactive Ajax-enabled Web applications. AsyncFileUpload is an ASP.NET AJAX Control that allows you asynchronously upload files to server, it uploads the file without any postback. The file uploading results can be checked both in the server and client sides.

ajax-file-upload
You can show the loading image while file uploading is in progress. Also you can save the uploaded file by calling the SaveAs() method in a handler for the server UploadedComplete event.

C#
  if (AsyncFileUpload1.HasFile)
  {
AsyncFileUpload1.SaveAs(@"C:\upload\" + AsyncFileUpload1.FileName);
  }

vb.net
  If AsyncFileUpload1.HasFile Then
AsyncFileUpload1.SaveAs("C:\upload\" + AsyncFileUpload1.FileName)
  End If

The following Asp.Net Ajax program shows how to integrate an AsyncFileUpload to your web application. To use the Ajax Control Toolkit in your Visual Studio project, you should add reference to the AjaxControlToolkit.dll in your project.

Default.aspx

 

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function clientMessage() {
document.getElementById("Label1").innerHTML = "File Uploaded Completed ";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="sm1" runat="server" />
<cc1:AsyncFileUpload ID="AsyncFileUpload1" runat="server"
UploadingBackColor="#82CAFA"
CompleteBackColor = "#FFFFFF"
OnUploadedComplete="doUpload"
OnClientUploadComplete="clientMessage"
ThrobberID="Throbber"  />
<asp:Image ID="Throbber" runat="server"
ImageUrl = "http://asp.net-informations.com/ajax/img/throbber.gif" />
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
<br />
</div>
</form>
</body>
</html>

Ajax ConfirmButtonExtender

ASP.NET AJAX Control Toolkit is an open-source project built on top of the Microsoft ASP.NET AJAX framework. The Ajax Control Toolkit contains a rich set of controls that you can use to build highly responsive and interactive Ajax-enabled Web applications.

confirmationButton
The Ajax Control Toolkit contains more than 40 controls. The ConfirmButton is a simple extender that displays the confirm box with a confirmation message and OK, Cancel button also catches clicks on a button and displays a message to end user.

To use the Ajax Control Toolkit in your Visual Studio project, you should add reference to the AjaxControlToolkit.dll in your project.

Default.aspx

 

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
        <br />
        <asp:Label ID="Label2" runat="server" Text="">
        </asp:Label>
        <br /><br />
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:Button ID="btnConfirm" runat="server" Text="Show Server Time"
            OnClick="btnConfirm_Click" />
            <asp:ConfirmButtonExtender ID="ConfirmButtonExtender1" runat="server"
            TargetControlID="btnConfirm"
            ConfirmText="Dyou want to see current server time ?"
            ConfirmOnFormSubmit="false">
            </asp:ConfirmButtonExtender>
            <br /><br />
            <asp:Label ID="lblMessage" runat="server">
            </asp:Label><br />
        </ContentTemplate>
        </asp:UpdatePanel>
</div>
</form>
</body>
</html>

CalendarExtender Validation

Using the Ajax Control Toolkit, you can build Ajax-enabled ASP.NET Web Forms applications by drag and drop Toolkit controls from the Visual Studio Toolbox onto an ASP.NET Web Forms page. Ajax toolkit has a CalendarExtender control which is very easily you can associate with a TextBox Control as well as a Button control.

Calendar-Validation
The following Asp.Net Ajax program validate a Date input from Ajax CalendarExtender control and shows the message to the client user. The validation performed by using JavaScript in the client side coding.

  

function verifyDate(sender,args){
    var d = new Date();
    d.setDate(d.getDate() - 1);
    if (sender._selectedDate < d)
    {
        alert("Date should be Today or Greater than Today");
        sender._textbox.set_Value('')
    }
}

You can copy and paste the following source code and run the program. To use the Ajax Control Toolkit in your Visual Studio project, you should add reference to the AjaxControlToolkit.dll in your project.

Default.aspx

  

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
    <script type="text/javascript">
        function verifyDate(sender,args){
            var d = new Date();
            d.setDate(d.getDate() - 1);
            if (sender._selectedDate < d)
            {
                alert("Date should be Today or Grater than Today");
                sender._textbox.set_Value('')
            }
        }
    </script>
</head>
<body>
<form id="form1" runat="server">
<div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:Label ID="Label1" runat="server" Text="Click Select Date Button to view Calendar"></asp:Label>
        <br />
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
   <asp:Button ID="Button1" runat="server" Text="Select Date" />
        <asp:CalendarExtender ID="CalendarExtender1" runat="server"
        TargetControlID="TextBox1" PopupButtonID="Button1"
        OnClientDateSelectionChanged="verifyDate" />
</div>
</form>
</body>
</html>