Wrox Programmer Forums
|
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 21st, 2009, 06:32 AM
Authorized User
 
Join Date: Jun 2008
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to workidoo
Default Date Validation Check

<form id="form1" runat="server">
<div>
Arrival Date:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>&nbsp;
<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>
&nbsp;
<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..
 
Old March 21st, 2009, 09:55 AM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Page_Load is too late to set MinimumValue and MaximumValue. Use Page_Init instead.

Code:
 Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
     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
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
 
Old March 21st, 2009, 11:02 AM
Authorized User
 
Join Date: Jun 2008
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to workidoo
Default

Thanks for the tip!

Btw it works with load too I just forgot to add HandlesMe.Load
__________________
http://www.workidoo.com
 
Old March 21st, 2009, 11:13 AM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Oh yeah, I didn't see that you forgot the handler. Should have looked more closely...
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}





Similar Threads
Thread Thread Starter Forum Replies Last Post
JS to check for form Validation does not work - pl jennypretty Classic ASP Basics 4 December 11th, 2008 11:18 PM
SQL Install Validation Check Sebastiaan SQL Server 2000 0 March 8th, 2006 10:37 AM
Need to check date a_rajasekhar Javascript How-To 1 March 25th, 2005 03:39 AM
email validation check if it's correct? xristina Javascript 2 October 14th, 2004 01:51 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.