Require entry for Calendar control

D

David Thielen

Hi;

I have:
<asp:Calendar ID="mapCalendarValue" runat="server"
Visible="false"></asp:Calendar>
<asp:RequiredFieldValidator ID="mapCalValidator" runat="server"
ErrorMessage="RequiredFieldValidator"
ControlToValidate="mapCalendarValue"></asp:RequiredFieldValidator>

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?
 
D

David Thielen

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.
 
W

Walter Wang [MSFT]

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#
http://support.microsoft.com/kb/310145


Regards,
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.
 
S

swetha

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 !
Regards,
M.Swetha
 
S

swetha

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:TextBox>

<asp:ImageButton ID="btnDate"
runat="server" OnClick="ClickDate"
ImageUrl="~/Images/Calendar_scheduleHS.png"
/>
<div style ="z-index:2;
position:absolute;top:450px; left:996px;">
<asp:Calendar ID="TodayDate"
OnSelectionChanged="DateEntry" runat="server" BackColor="White"
BorderColor="#3366CC"
BorderWidth="1px" CellPadding="1"
DayNameFormat="Shortest"
Font-Names="Verdana" Font-Size="8pt"
ForeColor="#003399" Height="200px"
Width="220px" Visible="false" DayHeaderStyle-Wrap="true">
<SelectedDayStyle
BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<SelectorStyle BackColor="#99CCCC"
ForeColor="#336666" />
<WeekendDayStyle
BackColor="#CCCCFF" />
<TodayDayStyle BackColor="#99CCCC"
ForeColor="White" />
<OtherMonthDayStyle
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:Calendar>

</div>

<asp:RequiredFieldValidator ID="rfvDate"
runat="server" Text="Please select a
date from the calender menu!"
ControlToValidate="txtDate">
</asp:RequiredFieldValidator><br />
Regards,
M.Swetha
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top