View Single Post
  #1 (permalink)  
Old December 16th, 2010, 08:53 AM
Arcy Arcy is offline
Registered User
Join Date: Nov 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default FindControl() doesn't find control in a detailsView

I am trying to set the focus on a textbox in a detailsView when its current mode is Insert or Edit.
Here is the template field in the .aspx file:
                                        <asp:TemplateField HeaderText="<%$ Resources:Tabelas, Cadeiras.NomeCadeira %>" SortExpression="NomeCadeira">
                                                <asp:TextBox ID="NomeCadeira" runat="server" Text='<%# Bind("NomeCadeira") %>'></asp:TextBox>
                                                <asp:TextBox ID="NomeCadeira" runat="server" Text='<%# Bind("NomeCadeira") %>'></asp:TextBox>
                                                <asp:Label ID="Label1" runat="server" Text='<%# Bind("NomeCadeira") %>'></asp:Label>
                                            <HeaderStyle Font-Bold="True" HorizontalAlign="Right" />
                                            <ItemStyle HorizontalAlign="Left" />
I tryed to use the following code in the DetailsView ModeChanged event, in the Page_Load event and in the Page_LoadComplete event:
        If DetailsView1.CurrentMode = DetailsViewMode.Insert Or DetailsView1.CurrentMode = DetailsViewMode.Edit Then

            Dim textBoxNomeCadeira = CType(FindControl("NomeCadeira"), TextBox)

        End If
but the textBoxNomeCadeira is always set to Nothing, meaning that the FindControl() function doesn't find the textBox "NomeCadeira".
How should I reference the textBox in the detailsView, in Insert or Edit Mode, to set the focus to it?