Require entry for Calendar control

Discussion in 'ASP .Net Web Controls' started by David Thielen, May 28, 2006.

  1. Hi;

    I have:
    <asp:Calendar ID="mapCalendarValue" runat="server"
    <asp:RequiredFieldValidator ID="mapCalValidator" runat="server"

    which gives me:
    [HttpException (0x80004005): Control 'mapCalendarValue' referenced by the
    ControlToValidate property of 'mapCalValidator' cannot be validated.]

    How can I require a selected date in the calendar control?
    David Thielen, May 28, 2006
    1. Advertisements

  2. ps - I know that this control defaults to 1/1/1 - I want a validator that
    requires a selection other than the default - and if the default changes,
    knows that too.
    David Thielen, May 28, 2006
    1. Advertisements

  3. Hi David,

    Thank you for post!

    Not all Web form controls can be used in conjunction with the validation
    controls. In order to be used with the validation controls, the control
    must have a ValidationProperty attribute. The ValidationProperty attribute
    tells the validation controls the value to validate against.

    The Calendar control is one of the controls that cannot be validated in its
    original state. In many cases, however, it is necessary to be able to
    validate the user selection in the Calendar control.

    There are two solutions to this problem. The first is to write a custom
    validation control. The second is to extend the Calendar control so that it
    can be used with the built-in validation controls. Following KB article
    addresses the second solution:

    #How to extend a Web form control to work with the validation controls by
    using Visual C#

    Walter Wang
    Microsoft Online Community Support

    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Walter Wang [MSFT], May 29, 2006
  4. David Thielen

    swetha Guest

    Hi david ,
    I guess u need to ass a text box before ur calender and then take the
    control id on text and then validate it !
    swetha, Oct 3, 2010
  5. David Thielen

    swetha Guest

    Hi david ,
    I belive u need to take a text box before ur calender and then take the
    control id on text and then validate it !
    It worked for me
    <asp:TextBox ID="txtDate"
    runat="server" PropertyName="Text"
    Text='<%# Bind("Date") %>'>

    <asp:ImageButton ID="btnDate"
    runat="server" OnClick="ClickDate"
    <div style ="z-index:2;
    position:absolute;top:450px; left:996px;">
    <asp:Calendar ID="TodayDate"
    OnSelectionChanged="DateEntry" runat="server" BackColor="White"
    BorderWidth="1px" CellPadding="1"
    Font-Names="Verdana" Font-Size="8pt"
    ForeColor="#003399" Height="200px"
    Width="220px" Visible="false" DayHeaderStyle-Wrap="true">
    BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
    <SelectorStyle BackColor="#99CCCC"
    ForeColor="#336666" />
    BackColor="#CCCCFF" />
    <TodayDayStyle BackColor="#99CCCC"
    ForeColor="White" />
    ForeColor="#999999" />
    <NextPrevStyle Font-Size="8pt"
    ForeColor="#CCCCFF" />
    <DayHeaderStyle BackColor="#99CCCC"
    ForeColor="#336666" Height="1px" />
    <TitleStyle BackColor="#003399"
    BorderColor="#3366CC" BorderWidth="1px"
    Font-Bold="True" Font-Size="10pt"
    ForeColor="#CCCCFF" Height="25px" />


    <asp:RequiredFieldValidator ID="rfvDate"
    runat="server" Text="Please select a
    date from the calender menu!"
    </asp:RequiredFieldValidator><br />
    swetha, Oct 3, 2010
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.