Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Professional ASP.NET 4 : in C# and VB
| Search | Today's Posts | Mark Forums Read
BOOK: Professional ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Professional ASP.NET 4 in C# and VB by Bill Evjen, Scott Hanselman, Devin Rader; ISBN: 9780470502204
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old December 16th, 2010, 08:53 AM
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

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
  #2 (permalink)  
Old December 16th, 2010, 11:47 AM
Registered User
 
Join Date: Nov 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Eventually I found that using the DataBound event of the DetailsView solved the problem.
Probably in the other events used (ModeChanged, Page_Load and Page_LoadComplete) the controls are still not available for the FindControl() function. (??!!)


Similar Threads
Thread Thread Starter Forum Replies Last Post
DetailsView Data Control behaviour mat41 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 6 November 1st, 2010 03:18 AM
DetailsView control stormage BOOK: Beginning ASP.NET 4 : in C# and VB 1 November 1st, 2010 03:17 AM
DetailsView Control on ManageCategories.aspx pinch BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 October 6th, 2007 09:15 PM
DetailsView Control Showkkath ASP.NET 1.x and 2.0 Application Design 2 August 21st, 2006 07:49 AM
Can not FindControl("ControlID") when the control kalchev ASP.NET 2.0 Basics 1 April 15th, 2006 07:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.