Hi,
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:
Code:
<asp:TemplateField HeaderText="<%$ Resources:Tabelas, Cadeiras.NomeCadeira %>" SortExpression="NomeCadeira">
<EditItemTemplate>
<asp:TextBox ID="NomeCadeira" runat="server" Text='<%# Bind("NomeCadeira") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="NomeCadeira" runat="server" Text='<%# Bind("NomeCadeira") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("NomeCadeira") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle Font-Bold="True" HorizontalAlign="Right" />
<ItemStyle HorizontalAlign="Left" />
</asp:TemplateField>
I tryed to use the following code in the DetailsView ModeChanged event, in the Page_Load event and in the Page_LoadComplete event:
Code:
If DetailsView1.CurrentMode = DetailsViewMode.Insert Or DetailsView1.CurrentMode = DetailsViewMode.Edit Then
Dim textBoxNomeCadeira = CType(FindControl("NomeCadeira"), TextBox)
textBoxNomeCadeira.Focus()
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?
Thanks