This is a migrated thread and some comments may be shown as answers.

RequiredFieldValidator for RadCalendar

4 Answers 71 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Sonia
Top achievements
Rank 1
Sonia asked on 09 Jul 2014, 11:45 AM
Hello,

Is it posible to validate if there is any selected date in a RadCalendar?

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 09 Jul 2014, 12:04 PM
Hi Sonia,

Please try to use CustomValidator to achieve your scenario.

ASPX:
<telerik:RadCalendar ID="RadCalendar1" runat="server">
</telerik:RadCalendar>
<asp:CustomValidator ID="CustomValidator1" runat="server" EnableClientScript="true"
    ClientValidationFunction="validateCalendar" ErrorMessage="Select Any Date">
</asp:CustomValidator>
<asp:Button ID="Button1" Text="Postback" runat="server" />

JavaScript:
function validateCalendar(sender, args) {
    var calendar = $find("<%=RadCalendar1.ClientID%>");
    if (calendar.GetSelectedDates().length == 0) {
        args.IsValid = false;
        return false;
    }
    return true;
}

Thanks,
Princy.
0
Sonia
Top achievements
Rank 1
answered on 10 Jul 2014, 05:56 AM
Thank you Princy, it works as expected.
0
Sonia
Top achievements
Rank 1
answered on 24 Oct 2014, 11:35 AM
Hi Princy,

How can i validate calendar when it is inside an InsertItemTemplate of a RadGrid? I mean I do not know RadCalendar ClientID in advance.
0
Sonia
Top achievements
Rank 1
answered on 28 Oct 2014, 12:53 PM
I have found the solution..., I share here in case it can be useful for other people.

In code-behind:
        protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
                RadCalendar semana = (RadCalendar)item.FindControl("Semana");
                CustomValidator semanaValidator = (CustomValidator)item.FindControl("Semana_CustomValidator");
                Page.ClientScript.RegisterExpandoAttribute(semanaValidator.ClientID, "ClientID", semana.ClientID, false);
        }

Javascript:
            function validateCalendar(sender, args) {
                var calendar = $find(sender.ClientID); //document.getElementById(sender.ClientID);
                if (calendar.GetSelectedDates().length == 0) {
                    args.IsValid = false;
                    return false;
                }
                return true;
            }


Tags
Calendar
Asked by
Sonia
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Sonia
Top achievements
Rank 1
Share this question
or