How To Validate Calendar Control in 2.0

create a textbox and default all colours to white (or whatever you need to hide). Create an event for OnSelectionChange on the calendar control.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ValidateCalControl.aspx.cs"
Inherits="ValidateCalControl" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<html xmlns="" >
<head runat="server">
   <title>Untitled Page</title>
   <form id="form1" runat="server">
   <asp:Calendar ID="Cal1" runat="server"
  <asp:TextBox ID="txtCal" runat="server" BackColor="White" BorderColor="white"
  <asp:RequiredFieldValidator ID="Req1" runat="server"
ControlToValidate="txtCal" ErrorMessage="Select Date"></asp:RequiredFieldValidator>
  <asp:Button ID="btnTest" runat="server" Text="Test" />
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 ValidateCalControl : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)

    protected void Cal1_SelectionChanged(object sender, EventArgs e)
        txtCal.Text = Cal1.SelectedDate.ToShortDateString();

Next Post Previous Post
No Comment
Add Comment
comment url