Tippu
Tippu

Reputation: 1261

Change the calenderextender default date

I have FROM DATE and TO DATE in a web form both are using the ajax calenderextender. When users select the FROM DATE and I want to default the TO DATE calenderextender date to FROM DATE +2 days. Is there any way to achieve this?

Thanks

Upvotes: 1

Views: 927

Answers (1)

Waqas
Waqas

Reputation: 6802

You can use javascript to set the SelectedDate property of "To Date" Calendar in OnClientShowing event. This is how you can do this:

in markup:

<cc1:CalendarExtender ID="toDate" runat="server" TargetControlID="txtDate" Format="MM/dd/yyyy" OnClientShowing="setDefaultDate" />

in javascript:

function setDefaultDate(sender,args)
{
    if(sender._textbox.get_element().value == "")
    {
        var selectedDate = new Date(); //here i am using current date but you can get the selected date of From Calendar control and add +2 days
        sender._selectedDate = selectedDate;
    }
}

Upvotes: 2

Related Questions