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

GetGridServerElement

1 Answer 74 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kenneth
Top achievements
Rank 1
Kenneth asked on 02 Jul 2008, 07:23 PM
I think I just misunderstand the clientside model but here's what I'm trying to achieve.

I am trying to get a clientside reference to a raddatepicker in the editformtemplate of a radgrid. I've used the code previously provided in this forum to do this:

          //walks over all elements with the specified tag name inside our grid 
            //does not require registration, but is a bit more complex 
            function GetGridServerElement(serverID, tagName) 
            { 
                if (!tagName) 
                    tagName = "*"//* means all elements 
                     
                var grid = $get("<%=RadGrid1.ClientID %>"); 
                var elements = grid.getElementsByTagName(tagName); 
                for (var i = 0; i < elements.length; i++) 
                { 
                    var element = elements[i]; 
                    if (element.id.indexOf(serverID) >= 0) 
                        return element; 
                } 
            } 

When I call this function, it does return what looks like the correct object.

However, when I examine the returned object it does not have the methods or properties of the raddatepicker client side object.

i.e.

var rdp = GetGridServerElement("rdpStartDate","*")

returns a valid object and it seems to be related to what I want (one of the properties 'className' is equal to 'pickerWrapper_Telerik'), but it does not seem to be a raddatepicker object. I would have expected to be able to do something like this:

rdp.get_selectedDate()

But, it doesn't work. I think there is some relationships between the object a get back from GetGridServerElement() and the expected client object - but I can't figure it out.

Can you please help??

Thanks.

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 03 Jul 2008, 01:28 PM
Hi Kenneth,

This sample method seems it is returning the DOM object RadDatePicker, instead of the client object. Therefore, you do not have the client properties and methods in the returned object. If you need to get a reference to the client RadDatePicker object, one approach you can take is the following:

1. In the ItemDataBound event, get the edited/inserted edit form item
2. Find the RadDatePicker server object using the FindControl() method and assign its ClientID to a hidden input on the page
3. In the javascript function that you use, get the value of the hidden input and use it as an argument for the document.getElementById() method to find the client RadDatePicker object.

Here is some sample code you can start from:

void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    if(e.Item is GridEditFormItem && e.Item.IsInEditMode) 
    { 
        GridEditFormItem item = (GridEditFormItem)e.Item; 
 
        //hiddenInput is the ID of the <input type="hidden"> element on the page 
        hiddenInput.Value =  (item.FindControl("RadDatePicker1"as RadDatePicker).ClientID 
    } 

And in the javascript function:

var pickerId = $get('hiddenInput').value; 
var radDatePicker = $find(pickerId); 


Greetings,
Veli
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Kenneth
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or