Try this code
<script type="text/javascript">
function AgeLimitCheck(sender,args)
{
var date1=new Date();
var date2 =sender._selectedDate;
var yearDiff=date1.getFullYear()-date2.getFullYear();
if (yearDiff < 18 || yearDiff > 50 )
{
alert("You age must be in 18 to 50");
sender._selectedDate = new Date();
sender._textbox.set_Value(sender._selectedDate.format(sender._format))
}
}
</script>
<asp:textbox id="TextBox1" runat="server" ></asp:textbox>
<cc1:calendarextender id="CalendarExtender1" runat="server" OnClientDateSelectionChanged="AgeLimitCheck" TargetControlID="TextBox1" >
</cc1:calendarextender>