Unable to use eval with RadDateTimePicker

3 posts, 0 answers
  1. Wize Owl
    Wize Owl avatar
    4 posts
    Member since:
    Dec 2009

    Posted 10 Mar 2010 Link to this post

    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);

    <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" />
  2. robertw102
    robertw102 avatar
    265 posts
    Member since:
    Jul 2007

    Posted 11 Mar 2010 Link to this post

    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>


    <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
  3. Wize Owl
    Wize Owl avatar
    4 posts
    Member since:
    Dec 2009

    Posted 11 Mar 2010 Link to this post

    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.
Back to Top