Hi Everyone,
I’ve searched a fair bit round and tried a number of potential solutions, suggested on their respective threads on various sites, to which none have worked for me.
My objective is to make sure the date entered, and to be stored, is not ‘less than’ (before) the present date
i.e. Booking a reservation for a restaurant.
The first is:
“The ControlToValidate property of ‘cvDate’ cannot be blank…”
I’ve tried specifying it in page_load and .aspx source, the same has happened in both, in addition to ValueToCompare. I cant understand why it cant detect it?
C# (ControltoValidate):
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Globalization;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net.Mail;
public partial class GenResEnquiry : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
IFormatProvider culture = new CultureInfo("en-GB", true);
Page.DataBind();
cvDate.ValueToCompare = DateTime.Today.ToShortDateString();
cvDate.ControlToCompare = txtDate.Text.ToString();
}
NB: Page.Databind(); was one of those suggestions in another thread which hasnt yet hindered or helped it. others included, in the .aspx page source, changing ValueToCompare=<%= … to #
ASPX:
<asp:TextBox ID=“txtDate” runat=“server”></asp:TextBox> <asp:Label ID=“lblDateFormat” runat=“server” Text=“(dd/mm/yyyy)” />
<asp:CompareValidator ID=“cvDate” runat=“server” Operator=“LessThan” Display=“Dynamic” Type=“Date” ErrorMessage=“Invalid Reservation date.” />
I had also tried the following in the btnSubmit_Click to the error with proceeds it
DateTime dateControl = Convert.ToDateTime(txtDate.Text);
DateTime valueControl = Convert.ToDateTime(DateTime.Today.ToShortDateString());
cvDate.ValueToCompare = valueControl.ToShortDateString();
cvDate.ControlToCompare = dateControl.ToShortDateString();
Error:
“The value ‘’ of the ValueToCompare property of ‘cvDate’ cannot be converted to type ‘Date’.”
Any help is much appreiciated!
Many Thanks,
Daniel