Not Another WordPress site

From the Blog

ago
11

How to forbid the user select a prior date with CalendarExtender

Posted by Felipe V. Rigo on agosto 11th, 2010 at 4:36 pm

AJAX Control Toolkit has a control called CalendarExtender.
This control shows a calendar to the user select a date when it clicks a textbox.
Many times we want the user select a future date.

To do that we just need to add the following javascript function:

function checkDate(sender,args)
{
if(sender._selectedDate < new Date())
{
alert(“You need to select a future date!”);
sender._selectedDate = new Date();
// select the current date again
sender._textbox.set_Value(sender._selectedDate.format(sender._format))
}

}

And then you need to add a reference to the javascript funcion in the CalendarExtender, like bellow:


<formid=”form1″ runat=”server”>
<asp:ScriptManager ID=”ScriptManager1″ runat=”server” />
<div>
<asp:TextBox ID=”TextBox1″ runat=”server”></asp:TextBox>
<cc1:CalendarExtender ID=”CalendarExtender1″
runat=”server” OnClientDateSelectionChanged=”checkDate” TargetControlID=”TextBox1″ />
</div>
</form>

Deixe um Comentário

  1.  

    |