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

Client side help required

2 Answers 133 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andy Green
Top achievements
Rank 2
Andy Green asked on 18 Jan 2016, 12:46 PM

On My RadGrid I have a checkbox column

<telerik:GridTemplateColumn UniqueName="colPrimaryProcedure" HeaderText="" ItemStyle-HorizontalAlign="Center"><HeaderStyle  HorizontalAlign="Center"  />
 <ItemTemplate>
  <asp:checkbox ID="chkPrimary" runat="server" />
 </ItemTemplate>
</telerik:GridTemplateColumn>

In the itemDatBound event I'm ading an onCLick attribute to fire a Javascript function.

Case "Treatment Codes"
 chkPri.Attributes.Add("onclick", [String].Format("setTreatment(this);"))
 chkPri.Text = "<span style='font-size:0px;line-height:0px;'>" & e.Item.DataItem("SpecialtyProcedureId") & "</span>"
 
In the Javascript file I'm getting the clicked on row, and also selecting a value in a RadComboBox, with Checkboxes set to true, and for each ticked row in the Rad Grid, I'm able to select a value in the combo box. This all works as expected.

var checkBox = document.getElementById(theBox.id);
var checkboxText = checkBox.parentElement.innerText.trim();
comboBoxPPFUWL.findItemByValue(checkboxText).set_checked(true);

 

What I want to do is if a box in unticked in the grid, is to un slect the row in the combo box, I'd have expected the following to work, but it doesn't.
comboBoxPPFUWL.findItemByValue(checkboxText).set_checked(false);

I'm using an old version of the controls 2014.2.618.40 and can't update because of breaking changes in the newer version.

Can anyone help.

2 Answers, 1 is accepted

Sort by
0
Andy Green
Top achievements
Rank 2
answered on 19 Jan 2016, 04:44 PM

Hi Guys

I have sorted this now - I had a var declared in the wrong place in my JS and was out of scope at the time I was trying to use it.

Andy

0
Eyup
Telerik team
answered on 20 Jan 2016, 09:27 AM
Hello Andy,

Generally, when a control is placed within a Content Page, RadGrid Template or another container which implements INamingContainer interface, its UniqueID and ClientID are modified, thus making it inaccessible on main Page level. The problem is similar when using server-side expressions like <%=txtTrackingNumber.ClientID%> in external JS files, which are not allowed.

On server-side, you need to use the FindControl method to access the control. You can use the
GridEditableItem item = RadGrid1.EditItems[0] as GridEditableItem; approach to get the currently edited item.

On client-side, you have several options to resolve this:

1. Hardcode the ClientID of the controls as the argument for $find() method.

2. Find the control using the findControl or findElement methods:
$telerik.findControl(document.documentElement, "txtTrackingNumber");

3. Use the client-side event handlers of the Telerik controls to get a reference to their objects:
Copy Code
<telerik:RadButton ... OnClientLoad="buttonLoad">
JavaScript:
Copy Code
var button;
function buttonLoad(sender, args) {
    button = sender;
}

In your case, you can use the second suggestion as an alternative to the global variables.

I hope this information will prove helpful.

Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Andy Green
Top achievements
Rank 2
Answers by
Andy Green
Top achievements
Rank 2
Eyup
Telerik team
Share this question
or