I have a user control named "UserControl_Attachments".
<%@ Register TagPrefix="UserControl_Attachments" TagName="Attachments" Src="/UserControls/UserControl_Attachments.ascx" %>
<UserControl_Attachments:Attachments ID="Attachments_Bulletin" runat="server" />
Inside the user control, I have a telerik:RadListView and in the "ItemTemplate" I have a telerik:RadButton with an ID="UC_DeleteAttachment_Button". Depending on the user login from the code behind I want to hide the button.
<telerik:RadListView runat="server" ID="UC_CurrentAttachments" AllowPaging="true" PageSize="40" OnNeedDataSource="UC_CurrentAttachments_NeedDataSource">
<LayoutTemplate>
<div style="max-width: 800px">
<asp:Panel ID="itemPlaceholder" runat="server">
<table>
</table>
</asp:Panel>
</div>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<a href="<%# Eval("AttachmentPath") %>" target="_blank">
<img src="<%# Eval("ImagePath") %>" width="<%# Eval("DisplayWidth") %>" height="<%# Eval("DisplayHeight") %>" />
</a>
</td>
<td>
<asp:Label runat="server" ID="Label_AttachmentName" Text='<%# Eval("DisplayName") %>' Font-Size="10px" />
</td>
<td>
<telerik:RadButton ID="UC_DeleteAttachment_Button" Width="25" runat="server" OnClick="UC_DeleteAttachment_Click" OnClientClicking="UC_Attachment_DeleteConfirm">
<Icon PrimaryIconCssClass="rbRemove"></Icon>
</telerik:RadButton>
</td>
</tr>
<asp:HiddenField ID="HiddenField_AttachmentPath" runat="server" Value='<%# Eval("AttachmentPath") %>' />
</ItemTemplate>
</telerik:RadListView>
Here is my code behind:
var CurrentAttachment_UC = (RadListView)Attachments_Bulletin.FindControl("UC_CurrentAttachments");
var CurrentAttachmentDeleteButton = (RadButton)CurrentAttachment_UC.FindControl("UC_DeleteAttachment_Button");
if (CurrentAttachmentDeleteButton != null)
CurrentAttachmentDeleteButton.Visible = false;
I've tried several things and still I can't find the control. It is always null. Is there anyway I can hide the button? Thanks in advance.
The best practise for finding a control within a RadListView is to use the ItemCreated event or ItemDataBound event for the RadListView: