0

I'am trying to hide/show the edit/save button in a ASP.NET Template. so i want the edit button too show when no row is selected, and then hide it on click and then make the save button visable instead.
How do I access and update the attribute?
The solution ive tried just gives me "Null"

what i have:

<ItemTemplate>
     <asp:ImageButton ID="ImageButtonEdit" runat="server" CommandName="Edit" ImageUrl="loginstyling/images/Edit.png"/>
     <asp:ImageButton ID="ImageButtonUpdate" runat="server" CommandName="Update" ImageUrl="loginstyling/images/Save.png" OnClick="ImageButtonUpdate_Click" Visible="true"/>
     <asp:ImageButton ID="ImageButtonDelete" runat="server" CommandName="Delete" ImageUrl="loginstyling/images/Remove.png" visible="false" />
</ItemTemplate>

what ive tried behind:

protected void ImageButtonUpdate_Click(object sender, ImageClickEventArgs e)
{
    ImageButton test = (ImageButton)GridView1.FindControl("ImageButtonUpdate");
    test.Attributes.Add("Visible", "False");

}

3 Answers3

0

Try if this works:

    test.Visible = false;
jashajasha
  • 13
  • 3
0

Are you sure that the .FindControl("ImageButtonUpdate");returns a valid object?

Since it returns null check this other post FindControl() return null , it seems to be the same problem you have encountered.

Community
  • 1
  • 1
jcsmata
  • 68
  • 1
  • 6
0

Try using RowDataBoundEvent for GridView, if it works:

protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
   if (e.Row.RowType == DataControlRowType.DataRow)
    {
        ImageButton test = (ImageButton)e.Row.FindControl("ImageButtonUpdate");
        test.Visible = false;
    }
}
user5434084
  • 149
  • 1
  • 8
  • did not work sadly. updated the question to clarify what i want, as this isnt the way for me :-) – Mathias Rønnow Nørtoft Nov 28 '16 at 18:19
  • check this solution if it helps you. The question is similar to hide/show [link](http://stackoverflow.com/questions/17646427/image-button-hide-and-un-hide) On a side note, you don't have an onClick event on your 'edit' imagebutton to hide and no 'save' button in your itemtemplate to be displayed. As what you say in your question and is shown in the code you provided. – user5434084 Nov 28 '16 at 18:43
  • thanks i will look into the solution. uhm yeah ive only added the code for the update button for now, trying to make that work. – Mathias Rønnow Nørtoft Nov 28 '16 at 18:47