Search code examples
asp.nettextboxformviewfindcontrol

Find a textbox inside panel which is inside FormView


The formview has more than 1 Panels. My textbox is in the first panel. If I use this

TextBox myTxtBox = (TextBox)myformView.Row.FindControl("pnlID").FindControl("mytextbox"); <- does not work

Panel mypanel = (Panel)myformView.Row.FindControl("pnlID"); <- this works
TextBox myTxtBox = (TextBox) FindControlRecursive(mypanel,'mytextbox'); <-- this does not work

Can someone help? As as side question, I used a function FindControlIterative but I do not know which references to include for LinkedList


Solution

  • The following works for me:

    Markup

    <asp:FormView ID="formView1" runat="server">
        <ItemTemplate>
            <asp:Panel ID="pnlID" runat="server">
                <asp:TextBox ID="mytextbox" runat="server"></asp:TextBox>
            </asp:Panel>
        </ItemTemplate>
    </asp:FormView>
    

    Code behind

    TextBox myTxtBox = (TextBox)FindControlRecursive(formView1,"mytextbox");