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

Controls in GridTemplateColumn shifting ClientID if in RadWindow ContentTemplate

3 Answers 53 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 1
Dan asked on 10 May 2017, 04:26 PM

I have been getting reports of an odd problem for a few months now - where some of our grids seem to be acting up.  I am not sure if it was a change in this most recent release or the one before that - but something has changed.  Hoping you guys can help

 

Here is the scenario:

 - We have RadGrids inside RadWindow / ContentTemplate areas on a screen.

 - These grids use GridTemplateColumns with various Rad controls inside each column - e.g. RadCombobox and RadNumericTextbox

 - On page load we bind data to these grids (along with other things on the main screen)

 - On the OnItemDataBound event of the RadGrid - we find the controls in each column, set their values if needed - and for clientside processing we set attributes on some controls to reference other controls on the same line.  For example, if the first column is a RadCombobox with two options, and the next column is a RadNumericTextbox that will display a default value when the value of the RadCombobox changes - then we get the ClientID of the RadCombobox and save it as an attribute on the RadCombobox

 - Following this example - we wire up the OnClientSelectedIndexChanged of the RadCombobox - and handle the setting of the default value for the RadNumericTextbox from javascript - to make it quick and excel like... the user just tabs through the fields - and this event does something like this:

         var myRadNumeric = $find(sender.get_attributes().getAttribute('myRadNumeric ')); 

         myRadNumeric.set_value(defaultValue);

 - The idea is to have the grid act more like Excel - so the user can just tab through and change data in each control

 

And here is the problem:

In the past this has always worked - AND still does - UNLESS the RadGrid is in a RadWindow/ContentTemplate.  Oddly in this scenario the ClientIDs of the controls in the GridTemplateColumns that we read and saved from the RadGrids OnItemDataBound event CHANGES once the screen is rendered...  so javascript cannot $find it...  

We have found we can fix this by making a server call back after displaying the RadWindow (from javascript radopen())  - doing a Rebind() on the grid in question - at that point all ClientIDs are correct on both client and server...

 

I hope you followed that - it is a bit elaborate of a scenario.  I believe we picked up this method of handing Excel like interactions with the RadGrid from an older Forum thread or suggestion - but we are not clear if the behavior we are seeing is 

 

 

3 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 11 May 2017, 01:44 PM

Hello Dan,

I advise that you do not put a grid in the ContentTemplate of the RadWindow if it is in a RadWindowManager, as noted at the end of this article: http://docs.telerik.com/devtools/aspnet-ajax/controls/window/getting-started/using-radwindow-as-controls-container.

Also, as noted there - the RadWindow ContentTemplate is an INamingContainer so it is expected to further change IDs.

What I would advise is that you traverse the DOM of the grid to get the next cell (jQuery and class selectors can help greatly with that) and get the .control attribute to reference the object., one example is available here: http://docs.telerik.com/devtools/aspnet-ajax/general-information/get-client-side-reference#using-jquery-selectors. For example, use something like sender.get_element().parents("tr").find(".desiredTargetCssClass").first()[0].control
 This will also reduce the markup you render, as you will no longer have to render a custom attribute to each element.

An alternative is to place the grid in its own page and load that in the RadWindow, instead of using the ContentTemplate. The ContentTemplate always renders on the page, while a separate page will only be requested when the RadWindow is shown, so this will improve performance.

Regards,

Marin Bratanov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Dan
Top achievements
Rank 1
answered on 11 May 2017, 03:53 PM

Hi Marin - thank you for the reply.  The application is question is Webform Forms site with about 1500 pages - no idea how many of them might put RadGrids inside of RadWindows within a RadWindowManager...  We have done some DOM crawling to find the related controls on a line - just weren't sure why the Client IDs were changing in this scenario.

Interesting note we had not seen at the end of the help article about RadWindowManager and RadGrid....  

Question on using a RadWindow outside of a RadWindowManager - aside from moving the RadWindow markup - are there any other differences?  This sounds like the quickest fix while we look at other alternatives.  Typically we use either radopen() or $find('<%RadWindow1.ClientID=%>').show() - will these still work targeting a RadWindow outside of a RadWindowManager?

0
Marin Bratanov
Telerik team
answered on 15 May 2017, 08:43 AM

Hello Dan,

The ClientIDs change because the ContentTemplate of the RadWindow is an INamingContainer, and the grid lifecycle and the RadWindow lifecycle are executed in different times so the ID change does not happen when you expect it. Hence, the warning in the documentation.

On opening that RadWindow once it is out of the RadWindowManager - $find().show() is the only way to do that now. Calling radopen() will use the window manager and you will get a different instance, not the one you expect.

Regards,

Marin Bratanov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Dan
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Dan
Top achievements
Rank 1
Share this question
or