Disable asp imagebutton

I am trying to make the image button in this table hide through the code located in C # (so that I can hide it after the action).

<asp:UpdatePanel runat="server" ID="upEmpListContainer" UpdateMode="Conditional"
    OnPreRender="upEmpListContainer_PreRender" OnInit="upEmpListContainer_Oninit">
    <ContentTemplate>

<asp:ListView ID="lvEmpList" OnItemDataBound="lvEmpList_ItemDataBound" OnDataBound="lvEmpList_DataBound"
            OnLayoutCreated="lvEmpList_LayoutCreated" runat="server" OnPreRender="lvEmpList_PreRender">
            <LayoutTemplate>
            <table class="formData_tb" cellspacing="0" style="margin: 0px; width: 100%;">
            <tr>
                <th colspan="9" class="currentManagerLabel" style="text-align: center">
                    <span>Currently displaying
                        <asp:Label ID="lblManager" runat="server" />
                        employees </span>
                    <asp:ImageButton ID="DrillUp" AlternateText="Move up in reporting heirarchy" runat="server"
                        CommandName="DrillDown" ImageUrl="~/images/icoDoubleArrowUp.gif" OnCommand="butDrillDown_Click" />
                </th>
            </tr>
        </table>
</LayoutTemplate>
</asp:ListView>
</ContentTemplate>
</asp:UpdatePanel>

I just can't access it from my id. I tried DrillUp.Enabled = false;, but Visual Studio says that it cannot resolve the "DrillUp" character.

+4
source share
3 answers

Your image button is inside the layout template, you cannot access it directly.

try it

ImageButton b = (ImageButton)lvEmpList.FindControl("DrillUp");
b.Visible = false;
+1
source

In your code behind the lvEmpList_ItemDataBound method, you need to use the following:

((e.Item.FindControl("DrillUp")) as ImageButton).Visible = false;

In addition, you should add verification that this is done only for DataItem elements, such as:

if (e.Item.ItemType == ListViewItemType.DataItem)
{
    ((e.Item.FindControl("DrillUp")) as ImageButton).Visible = false;
}
0

: 1 - aspx 1 - 2- , asp: imagebutton...

0

Source: https://habr.com/ru/post/1583786/


All Articles