tags:

views:

55

answers:

1

Hi

I am Using an AJAX calendar extender as following.

* Date

<asp:TextBox ID="txtCalControl" runat="server" Visible="True" Enabled="false"
CssClass="inputText" ErrorKey="IsValidDate" ></asp:TextBox>
 <span >
<asp:Image ID="imbCaledar" runat="server" ImageUrl="~/Images/calendar.GIF" />
</span>
</td>
<td >
<ajaxToolkit:CalendarExtender ID="calDisplaydate" runat="server" TargetControlID="txtCalControl" PopupButtonID="imbCaledar" PopupPosition="BottomRight" >
</ajaxToolkit:CalendarExtender>
</td>

I want to set the calendar to a specific date(eg 14 feb 2007) when a user clicks on the image.

I tried selected date property in .cs but it is assigning the value to the text box.

following is the requirement i have to achieve

Field is blank, and doesn’t display any date as default setting. The user needs to select a date to populate in the field. Therefore, the field is blank until the user picks a date from the calendar.

By default, the calendar control when opened is set to current date 2 years back.

A: 

You can use the OnClientDateSelectionChanged handler combined with setting a BehaviorID so you can find the extender easier:

<ajaxToolkit:CalendarExtender ID="calDisplaydate" runat="server"
 TargetControlID="txtCalControl" PopupButtonID="imbCaledar" 
 PopupPosition="BottomRight" OnClientDateSelectionChanged="setDate" 
 BehaviorID="myDate">
</ajaxToolkit:CalendarExtender>

In javascript:

    <script type="text/javascript" language="javascript">
      function setDate(sender,args){
        var d = new Date(); //Today
        d.setYear(d.getYear() - 2); //2 years ago
        $find("myDate").set_selectedDate(d);
      }
    </script>
Nick Craver
Thanks a lot nick.. that works
SaveMe

related questions