I echo that sentiment. I've gone over dozens of threads that talk about using FindControl in Pre_Render(), Data_Bound(), and a whole bunch of other places, and this still doesn't work.
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:FormView ID="FormView1" runat="server" onprerender="FormView1_PreRender">
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:FormView>
</asp:Content>
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:FormView ID="FormView1" runat="server" onprerender="FormView1_PreRender">
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:FormView>
</asp:Content>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default2 : System.Web.UI.Page
{
protected void FormView1_ItemCreated(object sender, EventArgs e)
{
TextBox aText = (TextBox) Util.FindControl("TextBox1", Page.Controls);
TextBox myText = (TextBox)FormView1.FindControl("TextBox1");
myText.Text = "Hello!";
}
protected void FormView1_DataBound(object sender, EventArgs e)
{
TextBox myText = (TextBox)FormView1.FindControl("TextBox1");
myText.Text = "Hello!";
}
protected void FormView1_PreRender(object sender, EventArgs e)
{
TextBox myText = (TextBox)FormView1.FindControl("TextBox1");
myText.Text = "Hello!";
}
}
No matter where I try, FindControl is returning null. I'm also running 3.5 SP1. I have a hard time believing its the framework itself, but none of the solutions I've seen posted on the forums seem to work.