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

Setting Attributes on a RadDateInput for use on client-side?

2 Answers 82 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 02 Nov 2008, 12:35 AM

Howdy, y'all.  I'm sure I'm missing something really basic, here.  I'm trying to write some additional information to the client-side attributes for a raddateinput control.  (This is part of a larger project, writing a custom validator, etc).  I've simplified out to a basic web page illustrating my challenge.  Here's my ASPX:

<%@ Page Title="" Language="C#" AutoEventWireup="true" CodeBehind="test5.aspx.cs" Inherits="TASDashboard.Secured.test5" %> 
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %> 
<%@ Register assembly="Controls" namespace="TASDashboard" tagprefix="cc1" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml">  
<head id="Head1" runat="server">  
    <title>Untitled Page</title> 
</head> 
<body> 
<form runat="server">  
<script language="javascript" type="text/javascript">  
    function testFunction(sender, args) {  
        alert(sender.testAttribute); //shows as undefined  
    }  
</script> 
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">  
    </telerik:RadScriptManager> 
        <telerik:RadDateInput ID="RadDateInput1" Runat="server" DateFormat="HHmm"   
            Skin="Office2007">  
        </telerik:RadDateInput> 
    <asp:ValidationSummary ID="ValidationSummary1" runat="server" /> 
    <p> 
        <asp:Button ID="Button1" runat="server" Text="Button" /> 
    </p> 
</form> 
</body> 
</html> 
 

and here's my C#:

 

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Web;  
using System.Web.UI;  
using System.Web.UI.WebControls;  
 
namespace TASDashboard.Secured  
{  
    public partial class test5 : DashboardBasePage  
    {  
        protected void Page_Load(object sender, EventArgs e)  
        {  
            RadDateInput1.ClientEvents.OnValueChanged = "testFunction";  
            RadDateInput1.Attributes.Add("testAttribute""hello");  
 
        }  
    }  

And when I run it, and change the value of the raddateinput control, my javascript routine runs as expected, but sender.testAttribute is undefined.  Should I be looking somewhere else for testAttribute?

Thank you!
Scott

2 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 03 Nov 2008, 08:16 AM
Hello Scott,

Generally sender is the instance of the JavaScript object - you can try sender.get_element() instead!

Sincerely yours,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Scott
Top achievements
Rank 1
answered on 03 Nov 2008, 01:25 PM
Vlad -

Thank you.  That was ALMOST it.  (I'd forgotten how useful the IE Developer toolbar can be in times like this.)  Just for anyone else reading this later - it looks like there are three INPUT elements within a span, for each RadDateInput:

RadDateInput1_text
RadDateInput1
RadDateInput1_ClientState

get_element() gets me RadDateInput1, but the attribute was on the _text.  So my final javascript that goes with the example I posted is:

<script language="javascript" type="text/javascript">  
    function testFunction(sender, args) {  
        var elem = sender.get_element();  
        var attributedElem = document.getElementById(elem.id + '_text');  
        alert(attributedElem.testAttribute); //shows as hello  
    }  
</script> 

Thanks again,
Scott
Tags
Calendar
Asked by
Scott
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Scott
Top achievements
Rank 1
Share this question
or