Date Validation Check
<form id="form1" runat="server">
<div>
Arrival Date:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RangeValidator ID="RangeValidator1" runat="server"
Text="You must only select a date within the next two weeks."
ControlToValidate="TextBox1" Type="Date"></asp:RangeValidator><br />
<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 />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
</div>
</form>
Code Behind
Partial Class Chapter_4_dateValidationCheck
Inherits System.Web.UI.Page
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
End Class
I got the following error:
The value of property Maximum Value for RangeValidator1 can not convert to type Date
__________________
http://www.workidoo.com
Last edited by workidoo; March 21st, 2009 at 06:37 AM..
|