0

I am trying to change the visibility of a button which is inside a table in a formview. But I am unable to find the control.

UserControl Page

<asp:FormView ID="FormView1" runat="server" DataSourceID="ds1" DefaultMode="Edit" OnItemCommand="FormView1_ItemCommand">
    <EditItemTemplate>
        <table id="t1">
            <tr>
                <td >
                     <asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
                </td>
             </tr>
        </table>
 </EditItemTemplate>
</asp:formview>

I want to change the visibility of "InsertButton" to false.

Button btInsert = (Button)FormView1.FindControl("InsertButton");
        if (btInsert!=null)
        {
            btInsert.Visible = false;
        }

COuld Anyone, explain me how can i find the button control, I get the null value only I am able to find FormView, but not the Buton control

user1989
  • 217
  • 2
  • 13
  • have you looked at what you have written..? how are you going to find `InsertButton` when you are doing a `FindControl on InsertButton1` – MethodMan Jan 19 '15 at 21:26
  • You can find it only if the formview's [mode](http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.formviewmode%28v=vs.110%29.aspx) is edit. Check it's `CurrentMode` property. – Tim Schmelter Jan 19 '15 at 21:28
  • @MethodMan Its InsertButton not InsertButton1. – user1989 Jan 19 '15 at 21:42
  • yeah after you edited it.. it's now insert button.. so does it still not work..? have you stepped thru the code..? try reading this link too http://stackoverflow.com/questions/1485545/formview-findcontrol-object-reference-error – MethodMan Jan 19 '15 at 21:44
  • @MethodMan No, it still does not work – user1989 Jan 19 '15 at 21:48
  • did you read the post about if the data was bound or not.. where are you binding the data..? – MethodMan Jan 19 '15 at 21:50
  • Yes, I read it. My data gets bind where I declare the text boxes. But, I also want in Edit Mode and Insert Mode. – user1989 Jan 19 '15 at 21:56
  • On which event you are trying to change the visibility? – Kiran Varsani Jan 20 '15 at 03:47

0 Answers0