469,649 Members | 1,469 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,649 developers. It's quick & easy.

get value from asp:textbox inside Repeater

After 16 hours of frustration, I've managed to solve this problem for a
project I'm working on.

The 'trick' is set EnableViewState="False" for the asp:textbox inside
the Repeater control.

The problem is that by default the asp:textbox ViewState is True. This
means that the textbox value is automatically preserved between
postback (saved in the __VIEWSTATE hidden field and restored during a
page postback).

If EnableViewState="True", the FindControl finds a 'copy'
of the asp:textbox control with it's initial value; not the postback
value. The postback value (whatever you type in the textbox AFTER the
page has loaded seems to get overridden because there is already a
control in memory with your texbox name). In my case FindControl
returns the Text property of the textbox as "".

Anyway, here's the solution:

--------------------
-------------------- ASPX
--------------------
<asp:Repeater
ID="Repeater1"
EnableViewState="False"
runat="server">

<ItemTemplate>

<asp:TextBox
ID="txtFirstName"
runat="server"/>

</ItemTemplate>

</asp:Repeater>

--------------------
-------------------- C#
--------------------
foreach (RepeaterItem item in Repeater1.Items)
{
Response.Write( ((TextBox)item.Controls[1]).Text);
}

-------------------- OR

foreach (RepeaterItem item in Repeater1.Items)
{
TextBox FirstName = (TextBox)item.FindControl("txtFirstName");
Response.Write(FirstName.Text);
}

I'm using Visual Web Developer 2005 Express Edition Beta running .NET
version 2_0_50215 on Windows 2000 Professional.

Hope this helps,
Bill
da*****@rocketmail.com

08.16.2005

Nov 19 '05 #1
0 10105

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Peter Kirk | last post: by
5 posts views Thread by Scott Lyon | last post: by
3 posts views Thread by Kelly Leahy | last post: by
2 posts views Thread by Craig Buchanan | last post: by
reply views Thread by Luis Esteban Valencia | last post: by
8 posts views Thread by dhnriverside | last post: by
reply views Thread by CharlesA | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.