I believe the problem is because of how you are calling the FindControl
method. FindControl needs to know which Item it is looking in because a
DataList contains many copies of each Control that is in a template, so you
need to call it as a method of an Item. Here is an example of where I used
in some code of mine to set the Text property of a Label (my code is in
VB.NET, but it should be similar in C#)
Private Sub datResults_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataListItemEventArgs) Handles
datResults.ItemDataBound
CType(e.Item.FindControl("lblPhone1"), Label).Text = " "
End Sub
Notice that I used e.Item.FindControl when calling the FindControl method. I
don't know what event is calling your method, so if you need help figuring
out how to determine which Item called it, let me know. But something that
it looks like you need to read up on a little bit is Event Bubbling (this is
where you use the CommandName and CommandArgument properties of the
Button/LinkButton/ImageButton Controls). Good Luck!
--
Nathan Sokalski
nj********@hotmail.com http://www.nathansokalski.com/
"christof" <no****@nomail.de> wrote in message
news:uR**************@TK2MSFTNGP10.phx.gbl...
How to do it:
My page:
<asp:DataList ID="dataListRoleMembers" ...>
...
<FooterTemplate>
<asp:LinkButton ID="btnAddMember" runat="server"
OnClick="btnAddMember_Click">Add...</asp:LinkButton>
<asp:TextBox ID="txtAddMember" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:DataList>
Code behind:
protected void btnAddMember_Click(object sender, EventArgs e)
{
TextBox txtMember =
(TextBox)dataListRoleMembers.FindControl("txtAddMe mber");
...
}
txtMember is null, FindControl don't get it for me - why?
I've tried also:
Control ctrl = dataListRoleMembers.FindControl("txtAddMember");
but result was the same, null
Thanks for help!