Saturday, March 24, 2012

CalendarExtender: How to count days between two selected dates

Hi

How can I calculate the days between selected dates from 2 calendarExtender controls?

thank you

zipfeli

Are you calculating client side or server side?


Clientside. Actually I want to validate the days between two textboxt dates before postback. More than 30 days should give errormessage .


Hi,

Here is a sample for your reference:

function fun(e)
{
var ce1 = $find("ce1");
var start = ce1.get_selectedDate();
if(start == null)
return;
var ce2 = $find("ce2");
var end = ce2.get_selectedDate();
if(end == null)
return;

start.setDate(start.getDate() + 30);
if(start < end)
alert("invalid");
start.setDate(start.getDate() - 30);
}

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></div>
<ajaxToolkit:CalendarExtender ID="CalendarExtender1" BehaviorID="ce1" runat="server" TargetControlID="TextBox1"OnClientDateSelectionChanged="fun">
</ajaxToolkit:CalendarExtender>

<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="CalendarExtender2" BehaviorID="ce2" runat="server" TargetControlID="TextBox2" OnClientDateSelectionChanged="fun">
</ajaxToolkit:CalendarExtender>

Hope this helps. 
 

No comments:

Post a Comment