Using the RangeValidator control to test a string date value (VB.net) : RangeValidator « Validation « ASP.NET Tutorial






<%@ Page Language="VB" %>

<script runat="server">
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        RangeValidator1.MinimumValue = DateTime.Now.ToShortDateString()
        RangeValidator1.MaximumValue = DateTime.Now.AddDays(14).ToShortDateString()
    End Sub
    
    Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, _
      ByVal e As System.EventArgs)
        TextBox1.Text = Calendar1.SelectedDate.ToShortDateString()
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, _
      ByVal e As System.EventArgs)
        If Page.IsValid Then
            Label1.Text = "You are set to arrive on: " & TextBox1.Text
        End If
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Date Validation Check</title>
</head>
<body>
    <form id="form1" runat="server">
        Arrival Date:
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>&nbsp;
        <asp:RangeValidator ID="RangeValidator1" runat="server" 
                            ErrorMessage="select a date within the next two weeks." 
                            ControlToValidate="TextBox1" 
                            Type="Date"/>
        <br />
        Select your arrival date:<br />
        <asp:Calendar ID="Calendar1" 
                      runat="server" 
                      OnSelectionChanged="Calendar1_SelectionChanged"></asp:Calendar>
        <br />
        <asp:Button ID="Button1" 
                    runat="server" 
                    Text="Button" 
                    OnClick="Button1_Click" />
        <br />
        <asp:Label ID="Label1" runat="server"></asp:Label>        
    </form>
</body>
</html>








8.8.RangeValidator
8.8.1.RangeValidator checks whether the value falls between a minimum and maximum value
8.8.2.Set Minimum/Maximum Value, ErrorMessage, ControlToValidate, EnableClientScript for asp:RangeValidator (C#)
8.8.3.Manual Validation
8.8.4.Use asp:RangeValidator to check the value range in an asp:textbox
8.8.5.asp:RangeValidator is converted to JavaScript code after loading in client side
8.8.6.Using the RangeValidator control to test an integer value
8.8.7.Using the RangeValidator control to test a string date value (C#)
8.8.8.Using the RangeValidator control to test a string date value (VB.net)
8.8.9.RangeValidator for number and date
8.8.10.Birthday range