A Place to Learn Ur-self…


To use this ajax calender extender we need to install ajaxcontrols To know how to know click this after installing take a new project and  add new webform and add a scriptmanager and textbox to that webform add calender extender using smart tag on right corner of textbox: the code for that is shown below: then add stylesheet.css file from ajaxcontroltoolkit download add this link to web form. now textbox is attached with calender extender to see this run the application and get focus on textbox then calender will appear… Output will be like this:

Display Calender Using Calender Icon:

If U want to show calender on clicking on a calender button do the following place a imagebutton and give calender icon as imageurl and give popupbuttonid as imagebutton id

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:ImageButton ID="ImageButton1" runat="server" Height="22px" ImageUrl="~/calendericon.jpg" Width="29px" />
<asp:CalendarExtender ID="TextBox1_CalendarExtender" runat="server" Enabled="True" TargetControlID="TextBox1" PopupPosition="BottomRight" PopupButtonID="ImageButton1">

then the output will be like this: now click on button to display calender

Disable or Restrict User To select date upto Today:

if u want to restrict user to select date upto today only do the following:

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:ImageButton ID="ImageButton1" runat="server" Height="22px" ImageUrl="~/calendericon.jpg" Width="29px" />
<asp:CalendarExtender ID="TextBox1_CalendarExtender" runat="server" Enabled="True" TargetControlID="TextBox1" PopupPosition="BottomRight" PopupButtonID="ImageButton1" EndDate="2012-06-02">

OutPut:

Restrict User to select date between today and past 15 Days using RangeValidator:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ 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"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt; <head id="Head1" runat="server">
<title></title>
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
  <form id="form1" runat="server">
  <div>
  <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
  </asp:ToolkitScriptManager> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
  <asp:ImageButton ID="ImageButton1" runat="server" Height="22px" ImageUrl="~/calendericon.jpg" Width="29px" />
  <asp:CalendarExtender ID="TextBox1_CalendarExtender" runat="server" Enabled="True" TargetControlID="TextBox1"
  PopupPosition="BottomRight" PopupButtonID="ImageButton1" EndDate="2012-06-02"> </asp:CalendarExtender>
  <asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="Plese Select Date from past 15 days"
  ControlToValidate="TextBox1" Type="Date" Display="None"> </asp:RangeValidator>
  <asp:ValidatorCalloutExtender ID="RangeValidator1_ValidatorCalloutExtender" runat="server" Enabled="True" TargetControlID="RangeValidator1">
   </asp:ValidatorCalloutExtender>
   </div>
    </form>
    </body>
    </html>

CodeBehind:

RangeValidator1.MaximumValue = System.DateTime.Now.ToShortDateString();
RangeValidator1.MinimumValue = System.DateTime.Now.AddDays(-15).ToShortDateString();

OutPut:

======================================

Thanks.

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: