Displaying a Simple Popup Calendar

March 05, 2013 |

In this tutorial, you learn how to display a popup calendar when someone moves focus to a TextBox. You can use the calendar to select a particular date.

We'll create the popup calendar by following these steps (1) Add a ToolkitScriptManager (2) Add a TextBox control (3) Add an CalendarExtender

To learn how to install the Ajax Control Toolkit  see the Ajax control toolkit page


Step 1:
             
        Add a ToolkitScriptManager :

       Before you can use any of the Ajax Control Toolkit controls in a page, you first need to add a ToolkitScriptManager to the page. You can drag the ToolkitScriptManager from the Visual Studio Toolbox window onto the page. The ToolkitScriptManager is located in the Ajax Control Toolkit tab under the Toolbox.

  1. <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">  
  2. </asp:ToolkitScriptManager> 


Step 2:

 

Add a TextBox Control

The CalendarExtender works with a standard ASP.NET TextBox control. In Design view, drag a TextBox control from under the Standard tab in the Toolbox onto your page.

Next, change the ID of the TextBox control to txtStartDate. You can change the ID in the Properties window. The resulting source code looks like this:

  1. <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">  
  2. </asp:ToolkitScriptManager>  
  3.   
  4. <asp:TextBox ID="txtStartDate" runat="server"></asp:TextBox> 
 Step 3 :

Add a CalendarExtender

The next step is to apply a CalendarExtender control to the TextBox. Add the following CalendarExtender control to your page:

  1. <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">  
  2. </asp:ToolkitScriptManager>  
  3.   
  4. <asp:TextBox ID="txtStartDate" runat="server"></asp:TextBox>  
  5.   
  6. <asp:CalendarExtender   
  7.     ID="CalendarExtender1"   
  8.     TargetControlID="txtStartDate"   
  9.     runat="server" /> 

0 comments:

Post a Comment