I need to be able to prevent a user from posting a form if they have entered an invalid date (5/121/2008) with the rad date picker. I added a CompareValidator and the form still posts, but with an empty value. When the form reloads, the date picker is empty.
I've simplified the code and found the problem still exists.
and the code behind ....
I've simplified the code and found the problem still exists.
- Enter a bad date
- click the button
- Compare validator didn't complain about an invalid date
- Date picker is now empty
- Label has a large number indicating the information was posted
- represents the ticks of last time posted
- represents the ticks of last time posted
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> | |
<%@ Register Assembly="RadCalendar.Net2, Version=2.2.2.0, Culture=neutral, PublicKeyToken=a1432cd341173140" | |
Namespace="Telerik.WebControls" TagPrefix="rad" %> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" > | |
<head runat="server"> | |
<title>Untitled Page</title> | |
</head> | |
<body> | |
<form id="form1" runat="server"> | |
<div> | |
Last Submitted: | |
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br /> | |
<br /> | |
<rad:RadDatePicker DateFormat="MM/dd/yyyy" id="RadDatePicker1" runat="server" Culture="English (United States)"> | |
<dateinput skin=""></dateinput> | |
</rad:RadDatePicker> | |
<br /> | |
<br /> | |
<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="RadDatePicker1" | |
ErrorMessage="CompareValidator" Operator="DataTypeCheck" Type="Date"></asp:CompareValidator><br /> | |
<br /> | |
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div> | |
</form> | |
</body> | |
</html> | |
and the code behind ....
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 Button1_Click(object sender, EventArgs e) | |
{ | |
Label1.Text = DateTime.Now.Ticks.ToString(); | |
} | |
} | |