Click here to Skip to main content
15,607,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Collapse | Copy Code

1)two calendar control[fromdate and todate]...both are disabled at start
3)save button

--if i click the check box...the disabled calendar control becomes enabled...then we enter from and todate
--then if i save it should update

--<<<<<<<<<what i="" require="">>.

if i dont click the check box[that is both fromdate and todate are disabled and are left blank]. and then save it should save.


if i dont click the check box and when i am trying to save..both the calendar control required field validator message is firing..enter valid value in the fields

--i want these message to be displayed[on save button click] only when check box is clicked..and calendar control [both from and to date] is left blank.

----------------------aspx code-----------------------------------------------
                    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                            <td align="left" class="style2" colspan="4">
                                <asp:CheckBox ID="chkroleid" runat="server" Text="Assign Role For Particular Duration"
                                    OnCheckedChanged="chkroleid_CheckedChanged" Checked="false" AutoPostBack="true" />
                <tr id="FirstRow" runat="server">

                    <td class="lavel">
                        <asp:Label ID="ll_Appointment_Date" runat="server" Text="From Date"></asp:Label>
                    <td width="25%">
                        <uc3:CalendarControl ID="txt_Appointment_From_Date"  runat="server" ShowTime="true"
                    <td class="label" width="10%">
                        <asp:Label ID="Label2" runat="server" Text="To Date"></asp:Label>
                    <td width="25%">
                        <uc3:CalendarControl ID="txt_Appointment_To_Date" runat="server" ShowTime="true"
                            SetEnabled="false" />

--custom button panel is having save button--
<uc1:CustomButtonPanel ID="CustomButtonPanel1" align="right" runat="server" />
       <asp:ValidationSummary ID="ValidationSummary1" runat="server" HeaderText="You must enter a valid value in the following field(s):"
           ShowMessageBox="True" ShowSummary="False" />

so how to solve this?


I m little confused. Can you help me ?

--in user control.ascx i have this

<asp:RequiredFieldValidator ID="Date_rfv" runat="server" SetFocusOnError="true" ControlToValidate="txtCalendarValue"

-- in usercontrol.ascx.cs

public void SetDateValidators()
if (this.RfvDateErrorMsg.Trim().Length > 0)
Date_rfv.ErrorMessage = this.RfvDateErrorMsg.ToString();
Date_rfv.ErrorMessage = System.Configuration.ConfigurationSettings.AppSettings["Date_rfv"];

--in web config the message is declared [enter valid date]
<add key="Date_rfv" value="Enter required date value.">

so when checkbox is not checked.
then the validation below fires
and the the webconfig key message

--custom button panel is having save button--
<pre lang="xml">&lt;uc1:CustomButtonPanel ID=&quot;CustomButtonPanel1&quot; align=&quot;right&quot; runat=&quot;server&quot; /&gt;
       &lt;asp:ValidationSummary ID=&quot;ValidationSummary1&quot; runat=&quot;server&quot; HeaderText=&quot;You must enter a valid value in the following field(s):&quot;
           ShowMessageBox=&quot;True&quot; ShowSummary=&quot;False&quot; /&gt;</pre>

i get error like below

You must enter a valid value in the following field
Enter required date value
Enter required date value

--after reading your article i tried to do

i am trying to do validation on client side..

<asp:CheckBox ID="chkroleid" runat="server" Text="Assign Role For Particular Duration"
OnCheckedChanged="chkroleid_CheckedChanged" Checked="false" Onclick="clientValidation_Calendarcontrol();" AutoPostBack="true" />

function clientValidation_Calendarcontrol(source, arguments)

  if (chkroleid.checked)


  var ValidationSummary1 = document.getElementById('ValidationSummary1');
  ValidatorEnable(ValidationSummary1, false);


--but this is not working,,,
how to disable the validation summary [You must enter a valid value in the following field]

and the part that is declared in usercontrol which is linked with webconfig[Enter required date value]

--kindly help
Updated 26-Aug-13 3:02am

1 solution

So there are two ways , whther you want to disable from client side or from server side. If you want to do from server side then on checkbox checked eent do a post back or use ajax and enable/disable the validation.

You can do it from Client side. Disable it from javascript. I have written a detailed article on ASP.NET Validators

You can have a look Exploring ASP.NET Validators[^]
Share this answer
anurag19289 26-Aug-13 9:03am    
Brother i am little confused... i have updated the question

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900