Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Professional ASP.NET 4 : in C# and VB
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #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. (??!!)
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 08:01 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.