findcontrol inside a DataList returns an object but no data

R

Rimu Atkinson

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
 
R

Rimu Atkinson

and no, i am not over-writing the contents of the datalist on postback...
 
R

Rimu Atkinson

i found an incredible amount of other postings dealing with very similar
problems, so i thought i'd better show my solution.

any page can have only 1 <form runat=server>, and if you have more than 1,
then .net will cry about it and refuse to run your page.

however, .net WILL let you have an extra <form> (without the runat=server),
but it throws all your viewstates out of whack. in my case, my second <form>
was within the main <form> block, so it's not valid HTML, even....

R
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top