findcontrol on textbox returns empty string

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Rimu Atkinson (rimu1_at_paradise.net.removenospamthing.nz)
Date: 02/03/04


Date: Tue, 3 Feb 2004 16:16:37 +1300

hi all

i use FindControl to get a textbox, and i get a textbox object, but it's
.Text property is empty.

some background info: i have a DataList, which has a template column in it,
and in that template column i define a textbox.

<asp:TemplateColumn HeaderText="Quantity">
 <ItemTemplate>
  <asp:TextBox id="Quantity" runat="server" Columns="4" MaxLength="3"
Text='<%# DataBinder.Eval(Container.DataItem, "Quantity") %>' width="40px"
/>
 </ItemTemplate>
</asp:TemplateColumn>

Later on, i want to go through all the rows in the datalist (called MyList),
and do some processing based on the contents of the textboxes, which may
have been changed by the user.

For i = 0 To MyList.Items.Count - 1

Dim quantityTxt As TextBox = CType(MyList.Items(i).FindControl("Quantity"),
TextBox)

'do some stuff here

Next

quantityTxt.Text is always vbNullstring. i have tried
MyList.Items(i).Cells(2).FindControl("Quantity") as well, which makes no
difference.

any idea why??

any help very much appreciated.

thanks

Rimu



Relevant Pages

  • Re: findcontrol on textbox returns empty string
    ... > i use FindControl to get a textbox, and i get a textbox object, but it's ... > .Text property is empty. ... > some background info: i have a DataList, which has a template column in it, ... > and in that template column i define a textbox. ...
    (microsoft.public.dotnet.general)
  • RE: Databound Textbox vs. Width property
    ... "Arthur Dent" wrote: ... > I have a datagrid with a template column containing a databound textbox. ... > I also tried setting it to a set pixel width, ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: printing only part of a webform
    ... > just printing the contents of a textbox or label. ... > datagrid displays what the search returns with a template column to link ... but it opens a new page and pressing back does not take you ... > articles, there is a link on the right that says Print this page. ...
    (microsoft.public.dotnet.general)
  • Format text in Textbox asp1.1
    ... Hi i am using a datagrid and a template column. ... In the itemheader i have put 3 controle a text box, radiobuttonlist and another textbox. ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • findcontrol inside a DataList returns an object but no data
    ... i use FindControl to get a textbox, and i get a textbox object, but it's ... .Text property is empty. ... some background info: i have a DataList, which has a template column in it, ... and in that template column i define a textbox. ...
    (microsoft.public.dotnet.framework.aspnet)