Net-informations.com
SiteMap  | About    

CalendarExtender Validation

Using the Ajax Control Toolkit, you can build Ajax-enabled ASP.NET Web Forms applications by drag and drop Toolkit controls from the Visual Studio Toolbox onto an ASP.NET Web Forms page. Ajax toolkit has a CalendarExtender control which is very easily you can associate with a TextBox Control as well as a Button control.

Calendar-Validation

The following Asp.Net Ajax program validate a Date input from Ajax CalendarExtender control and shows the message to the client user. The validation performed by using JavaScript in the client side coding.

  

function verifyDate(sender,args){
    var d = new Date();
    d.setDate(d.getDate() - 1);
    if (sender._selectedDate < d)
    {
        alert("Date should be Today or Greater than Today");
        sender._textbox.set_Value('')
    }
}

You can copy and paste the following source code and run the program. To use the Ajax Control Toolkit in your Visual Studio project, you should add reference to the AjaxControlToolkit.dll in your project.

Default.aspx

  

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
	<title>Untitled Page</title>
    <script type="text/javascript">
        function verifyDate(sender,args){
            var d = new Date();
            d.setDate(d.getDate() - 1);
            if (sender._selectedDate < d)
            {
                alert("Date should be Today or Grater than Today");
                sender._textbox.set_Value('')
            }
        }
    </script>
</head>
<body>
	<form id="form1" runat="server">
	<div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:Label ID="Label1" runat="server" Text="Click Select Date Button to view Calendar"></asp:Label>
        <br />
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
	    <asp:Button ID="Button1" runat="server" Text="Select Date" />
        <asp:CalendarExtender ID="CalendarExtender1" runat="server"
        TargetControlID="TextBox1" PopupButtonID="Button1"
        OnClientDateSelectionChanged="verifyDate" />
	</div>
	</form>
</body>
</html>







net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.