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

Unable to use eval with RadDateTimePicker

2 Answers 81 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Wize Owl
Top achievements
Rank 1
Wize Owl asked on 11 Mar 2010, 12:42 AM
This is probably very simple and I am probably missing just the correct line that will make this work. I have writen a javascript function that I want to use with multiple RadDateTimePickers. I want to pass in the name of the RadDateTimePicker, eval the name to find the control and then run the rest of the script. I get the error "expression expected" when I do this. Any ideas?

function SetDate(pid, val) {
    //the following statement fails with "expression expected"
    //it is a mirror of the statement below that works except for variable substitution
    var radCal= eval('$find("<%='+pid+'.ClientID%>")');

    //the following statement works and is what I want replaced with the statement above this comment
    //even though the eval() doesn't actually do anything, I just wanted to make sure it would work in an eval()
    var radCal= eval('$find("<%=RadDateTimePicker1.ClientID%>")');

    //value in val looks like: 03/10/2010
    val = FormatDate(val);
    var pd = new Date(val);
    radCal.set_selectedDate(pd);
}

<a href="javascript:SetDate('RadDateTimePicker1', lastWeek());">Last Week</a>

<telerik:RadDateTimePicker ID="RadDateTimePicker1" runat="server" MinDate="2000/1/1" Width="170px" >
       <TimeView ID="TimeView1" StartTime="09:00" EndTime="17:00" Interval="0:15:0" runat="server" />
</telerik:RadDateTimePicker>    

2 Answers, 1 is accepted

Sort by
0
robertw102
Top achievements
Rank 1
answered on 11 Mar 2010, 03:41 PM
The reason it doesn't work is because you are trying to get the ClientID of a javascript object, which doesn't exist in the .NET context. If you want to pass the ClientID of the RadDateTimePicker, why not just change the line:

<a href="javascript:SetDate('RadDateTimePicker1', lastWeek());">Last Week</a>

with:

<a href="javascript:SetDate('<%=RadDateTimePicker1.ClientID%>', lastWeek());">Last Week</a>

and then in your SetDate method just do this:

var radCal= eval('$find(pid)');

I hope that helps
0
Wize Owl
Top achievements
Rank 1
answered on 11 Mar 2010, 06:04 PM
Thanks for the tip, Robert. I can't believe I didn't think of that. That's why I thought it was simple and I was just too involved in the project to see the simple solution. Thank you so much.
Tags
Calendar
Asked by
Wize Owl
Top achievements
Rank 1
Answers by
robertw102
Top achievements
Rank 1
Wize Owl
Top achievements
Rank 1
Share this question
or