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

RadGrid Finding Problem in Underlying Control

1 Answer 44 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Muhammad asked on 21 Aug 2012, 01:10 PM

I am using radgrid and in itemtempalte I have a dropdownlist and a label control. OnItemDatabound event I am passing the ids of dropdownlist and a label control to a javascript function. The functions finds the client ids of the dropdownlist and a label control but when I use document.getElementbyId for label control it gives me null.

Any help would be really appreciated.


function OnSelectedIndexChange(ddlTopic, lblTopic) {
       var ddl = document.getElementById(ddlTopic);
       var lbl = document.getElementById(lblTopic); // The problem occurs here 
       alert(lbl); = "none";       
<telerik:RadGrid ID="gvTopics" runat="server" Font-Names="Verdana" Font-Size="XX-Small"
                   Skin="Outlook" EnableEmbeddedSkins="true" GridLines="Vertical" AllowSorting="true"
                   AllowPaging="true" Width="99%" CellPadding="2" AutoGenerateColumns="False">
                   <MasterTableView CommandItemDisplay="Top">
                       <CommandItemSettings ShowAddNewRecordButton="false" />
<telerik:GridTemplateColumn SortExpression="Topic" HeaderText="Topic">
                                   <asp:LinkButton ID="lnkTopic" Text='<%# Bind("Topic") %>' runat="server"></asp:LinkButton>
                                   <telerik:RadToolTip ID="rttpTopics" Width="350" Height="100" HideEvent="ManualClose"
                                       TargetControlID="lnkTopic" RelativeTo="Element" Skin="Windows7" Position="TopRight"
                                       ManualClose="true" ShowEvent="OnClick" runat="server">
                                       <table width="100%">
                                               <td width="40%">
                                                   select topic :
                                                   <asp:DropDownList ID="ddlTopic" runat="server" Font-Names="Verdana" Font-Size="XX-Small"
                                                       ValidationGroup="selecttopic" AutoPostBack="false" />
                                                    <asp:RequiredFieldValidator ID="rfvTopic" runat="server" ErrorMessage="## please select a topic"
                                                       InitialValue="- please select -" ControlToValidate="ddlTopic" Font-Bold="True"
                                                       Font-Names="Arial" Font-Size="X-Small" SetFocusOnError="True" ValidationGroup="selecttopic" />
                                                   <telerik:RadTextBox ID="rtbTopicName" EmptyMessage="please enter topic name"
                                                   <asp:Label ID="lblTopicName" Text="TopicName" Visible="false" runat="server"></asp:Label>
                                                   <asp:Button ID="btnSaveTopic" CommandArgument='<%# Container.DataItem("id")%>' ValidationGroup="selecttopic"
                                                       CausesValidation="true" OnClick="btnSaveTopic_Click" Text="Save" runat="server" />
                           <asp:Label ID="Label5" runat="server" Text="no topics found"></asp:Label>
Protected Sub gvTopics_OnItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles gvTopics.ItemDataBound
       If TypeOf (e.Item) Is GridDataItem Then
           Dim ddlTopic As DropDownList = e.Item.FindControl("ddlTopic")
           Dim lblTopicName As Label = e.Item.FindControl("lblTopicName")
           ddlTopic.Attributes.Add("onChange", "return OnSelectedIndexChange('" & ddlTopic.ClientID & "','" & lblTopicName.ClientID & "');")
   End Sub

1 Answer, 1 is accepted

Sort by
Top achievements
Rank 2
answered on 22 Aug 2012, 04:47 AM
Hi Muhammad,

You got null for the Label in client side because you have set the Visible property of the Label to false.One suggestion is to set the Visible property to true and and make the Label 'display' to 'none' in the CSS.

<asp:Label ID="lblTopicName" CssClass="LabelDisplay" Text="TopicName" Visible="true" runat="server"></asp:Label>


Asked by
Top achievements
Rank 1
Answers by
Top achievements
Rank 2
Share this question