How to link ASP.NET AJAX Calender Extender with a Textbox

Today I am going to demonstrate an easy way to link ASP.NET AJAX Calender Extender with a textbox so that selecting date from calender is captured by the textbox.

Add asp.net textbox from toolbar on your page:
<asp:TextBox ID="DateTextBox" runat="server"  />

Now add asp.net image tag from toolbar on your page:
<asp:Image ID="Image1" runat="server" ImageUrl="Calendar_icon.png" />

This image tag will display a small icon of calender so that user can click on the calender icon to open up the calender tool.

Now add AJAX CalendarExtender tag on your page like this:
<ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="DateTextBox" PopupButtonID="Image1">
</ajaxToolkit:CalendarExtender>


If you notice in the above code I have highlighted (in bold) the part of AJAX CalendarExtender which is making connection with the textbox and image tag.

Your code should look like this:
<asp:TextBox ID="DateTextBox" runat="server"  />
<asp:Image ID="Image1" runat="server" ImageUrl="Calendar_scheduleHS.png" />
<ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="DateTextBox" PopupButtonID="Image1">
</ajaxToolkit:CalendarExtender>


Make sure you add this in your webconfig:

<pages>
      <controls>
        <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
        <add namespace="AjaxControlToolkit" assembly="AjaxControlToolkit" tagPrefix="ajaxToolkit"/>
      </controls>
    </pages>

That's all you need in order to make ASP.NET AJAX Calender tool work with your textbox.

About Author

Written By Lavish Kumar

Based out of New York, USA, Lavish Kumar is a full stack web developer by profession and founder of Striving Programmers, a trusted community for developers that offers a wealth of articles and forums to assist individuals with improving their software development skills.

Related Blog Posts
Leave your comment