4 Answers, 1 is accepted
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:
JavaScript:
Thanks,
Princy.
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.
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;
}
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;
}