ksummers
asked on
Range validator problem in C#.NET to check date range.
I am having a problem with a range validator which I had asked a question about a few weeks ago. Here is what is happening, and I actually created a simple ASP.NET page to test this with a textbox and a rangevalidator. I set the maximum value of the rangevalidator but it DOES NOT pop up a warning if I put in todays today, which it should. What am I doing wrong?
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls. WebParts;
using System.Web.UI.HtmlControls ;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
txtToDate.Text = DateTime.Now.AddDays(-1).T oShortDate String(); //Default to yesterday's date.
RangeValidator1.MaximumVal ue = DateTime.Now.AddDays(-1).T oShortDate String();
}
}
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.
using System.Web.UI.HtmlControls
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
txtToDate.Text = DateTime.Now.AddDays(-1).T
RangeValidator1.MaximumVal
}
}
check this
<asp:TextBox ID="TextBox1" runat="server"></asp:TextB ox><br />
<asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="Error!!!!!!"
Type="Date" ControlToValidate="TextBox 1" MaximumValue="1983-04-21" MinimumValue="1983-04-17"> </asp:Rang eValidator >
if i now put in 1983-04-23 it will alert me the error but a range inside the allowed range will work
Andrew
<asp:TextBox ID="TextBox1" runat="server"></asp:TextB
<asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="Error!!!!!!"
Type="Date" ControlToValidate="TextBox
if i now put in 1983-04-23 it will alert me the error but a range inside the allowed range will work
Andrew
ASKER
I have to set the maximum value in the code like I have it, but I do not get the error if I type in tomorrow's date 10/2/2007. I don't want to hardcode it. Why won't it get me the error?
I tried to change the date type but I get this error. Did you get this error with my code??
The value '' of the MinimumValue property of 'RangeValidator1' cannot be converted to type 'Date'.
I tried to change the date type but I get this error. Did you get this error with my code??
The value '' of the MinimumValue property of 'RangeValidator1' cannot be converted to type 'Date'.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Is there a way to specify the format then? I need it to be entered as mm/dd/yyyy and I need the validator to accept this and check it??
ASKER
<asp:TextBox ID="txtToDate" runat="server"></asp:TextB ox><br />
<asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="Error!!!!!!" Type="Date" ControlToValidate="txtToDa te" MaximumValue="2010-10-01" MinimumValue="1000-01-01"> </asp:Rang eValidator ></div>
Thanks, but I figured it out. I set the date and set the minimum to a crazy early date and set the maximum to yesterday's date using the datetime function. It works fine. I will award you the points.
<asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="Error!!!!!!"
Thanks, but I figured it out. I set the date and set the minimum to a crazy early date and set the maximum to yesterday's date using the datetime function. It works fine. I will award you the points.
<asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="RangeValidat
Type="Date"></asp:RangeVal