<telerik:RadGrid ID="Grid" runat="server" Skin="Metro" AllowAutomaticInserts="true" AllowAutomaticUpdates="true" AllowPaging="true" AllowMultiRowSelection="true" PageSize="25" EnableEmbeddedSkins="true"> <MasterTableView CommandItemDisplay="Top" EditMode="PopUp" ClientDataKeyNames="Id" DataKeyNames="Id" InsertItemPageIndexAction="ShowItemOnCurrentPage"> <Columns> <telerik:GridEditCommandColumn /> <telerik:GridBoundColumn DataField="Id" HeaderText="Id" UniqueName="Id" Display="false"></telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name"> </Columns> </MasterTableView> <PagerStyle AlwaysVisible="true"> </PagerStyle> <ClientSettings EnableRowHoverStyle="true"> <DataBinding Location="~/services/service.asmx" SelectMethod="List" SelectCountMethod="ListCount"> </DataBinding> <Selecting AllowRowSelect="true" /> </ClientSettings></telerik:RadGrid>
I have a couple of questions as it pertains to JavaScript and Telerik Ajax controls:
1 - How can I reference a control using a variable? For example, I'm using the following code to enable/disable a RadTextBox based on a checkbox:
<script type="text/javascript"> function enableDisableControl(bEnable) { var control = $find("<%= txt_ticketnumber.ClientID %>"); if (bEnable) { control.enable(); } if (!bEnable) { control.disable(); } }</script>
I would like to make this more modular by doing this:
<script type="text/javascript"> function enableDisableControl(bEnable, controlID) { var control = $find("<%= controlID.ClientID %>"); if (bEnable) { control.enable(); } if (!bEnable) { control.disable(); } }</script>
and then calling it from checkbox's onclick client event.
onclick="enableDisableControl(this.checked, 'txt_ticketnumber');"It works with standard ASP controls, but when I attempt to do this with Telerik controls I receive a null reference.
2 - How can I access ASP Ajax controls from a imported JavaScript. For example, the 1st example listed above works fine if its in the ASPX file wrapped in a RadScriptBlock. But if I move it to its own file (named something.js) and import it with the following code, I can no longer access controls. Its seems "out of scope". I've also tried wrapping it in a RadScriptBlack with no success.
<script type="text/javascript" src="Scripts/ControlNameLocator.js"></script>

function sortByStatus() {// var item = eventArgs.get_item(); // var strSort = item.get_value(); var combo = $find("<%= rcbStatus.ClientID %>"); var comboItem = combo.get_selectedItem(); var strSort = comboItem.get_value(); alert('Selected ' + comboItem.get_value()); if (strSort != 'Active') { window.location = 'meet-the-panel.aspx?paneltype=' + strSort; } else { window.location = 'meet-the-panel.aspx'; } }<telerik:RadComboBox ID="rcbStatus" runat="server" Skin="Black" EnableEmbeddedSkins="false" Width="220px" > <Items> <telerik:RadComboBoxItem Value="Active" Text="Current Panelists"/> <telerik:RadComboBoxItem Value="alumni" Text="Past Panelists"/> </Items></telerik:RadComboBox>Protected Sub ChangeBackColorIfImplied() Dim SelectedNum As Integer = -1 Dim SelectedString As String = "" Dim StringofUps As String = "" lblUpInfo.Text = "" Dim i As Integer For i = 1 To lbUp.Items.Count - 1 If lbUp.Items(i).Selected Then StringofUps = StringofUps & lbUp.Items(i).Value lbUp.Items(i).Attributes.Add("style", "background-color#FFFFFF") End If Next i Dim Flag As Boolean = False Dim mylistitem As ListItem For Each mylistitem In lbUp.Items Dim ListItemString As String = mylistitem.Value If InStr(StringofUps, ListItemString) > 0 Then If StringofUps <> ListItemString Then mylistitem.Attributes.Add("style", "background-color:#99FFFF") lblUpInfo.Text = "All entities and people highlighted in light blue will also receive this communication" End If Else mylistitem.Attributes.Add("style", "background-color:#FFFFFF") End If Next End Sub