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

Radgrid and Javascript

1 Answer 25 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Neepa
Top achievements
Rank 1
Neepa asked on 11 Sep 2012, 03:32 PM
<telerik:RadGrid ID="rgLabelManager" runat="server" Skin="ARC" AutoGenerateColumns="false" 
GridLines="None" AllowSorting="true" AllowPaging="true" PageSize="10" 
OnNeedDataSource="LabelManager_NeedDataSource" OnItemDataBound="LabelManager_ItemDataBound"
OnUpdateCommand="LabelManager_UpdateCommand" OnInsertCommand="LabelManager_InsertCommand">
<
PagerStyle Mode="NextPrevAndNumeric" />        
<MasterTableView Width="100%" AutoGenerateColumns="false" EditMode="InPlace" 
CommandItemDisplay="TopAndBottom">
<Columns>
<telerik:GridTemplateColumn  UniqueName="ContactName" SortExpression="LastName" HeaderText="Contact Name" 
ItemStyle-Width="60%" ItemStyle-HorizontalAlign="Left">
<ItemTemplate> <%#((String)DataBinder.Eval(Container.DataItem, "FirstName")).Substring(0,1).ToUpper()%>
<%
#((String)DataBinder.Eval(Container.DataItem, "FirstName")).Substring(1).ToLower()%>   
<%#((String)DataBinder.Eval(Container.DataItem, "LastName")).Substring(0,1).ToUpper()%>
<%
#((String)DataBinder.Eval(Container.DataItem, "LastName")).Substring(1).ToLower()%>
</ItemTemplate>
<EditItemTemplate>

<telerik:RadComboBox ID="rcbContactName" runat="server" EnableVirtualScrolling="true"
ShowMoreResultsBox="true" ItemsPerRequest="10" EnableLoadOnDemand="true" Width="400" 
OnClientItemsRequesting
="GenericRadCombo_OnClientItemsRequesting" 
OnClientItemsRequested
="rcbLookupContact_OnClientItemsRequested" 
OnClientDropDownClosing
="rcbLookupContact_OnClientDropDownClosing">
<
WebServiceSettings Method="LookupContact" Path="~/service/scriptservice.asmx" />
</telerik:RadComboBox> &nbsp;&nbsp;
<asp:LinkButton runat="server" ID="lbAdd" Text="Add New Contact" style="display:none;" 
OnClick="lnkAddContact_Click"></asp:LinkButton>
</EditItemTemplate>
</telerik:GridTemplateColumn> 

I want to access "lbAdd" from Javascript and keep getting error that lbAdd in not in the context. I've tried
$find('<%=lbAdd.ClientID %>')  and 
document.getElementById("<%=lbAdd.ClientID %>")

Please let me know if I'm missing something to access lbAdd - I need to change the display based on different conditions.

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 12 Sep 2012, 05:34 AM

Hi,

Please check the following code snippet I tried to access the LinkButton in the Javascript.

C#:

protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        GridEditableItem edit = (GridEditableItem)e.Item;
        LinkButton lbl = (LinkButton)edit.FindControl("lbAdd");
        RadGrid1.Controls.Add(new LiteralControl("<script type='text/javascript'>window['btn'] = '" + lbl.ClientID + "';</script>"));
    }
}

Javascript:

<script type="text/javascript">
    function testfns()
    {
        var linkbutton = document.getElementById(window['btn']);
    }
</script>

Thanks,
Princy.

Tags
General Discussions
Asked by
Neepa
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Share this question
or