Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > get value from asp:textbox inside Repeater

Reply
Thread Tools

get value from asp:textbox inside Repeater

 
 
datakix@gmail.com
Guest
Posts: n/a
 
      08-17-2005
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


08.16.2005

 
Reply With Quote
 
 
 
 
sanda sanda is offline
Junior Member
Join Date: May 2011
Posts: 1
 
      05-16-2011
Just want to say, 5 years later, this post still helps me tremendously. Got stuck on the same issue for textbox inside repeater and this one clears it all.

Thanks again.
 
Reply With Quote
 
 
 
 
JohnnyC JohnnyC is offline
Junior Member
Join Date: Aug 2011
Posts: 1
 
      08-08-2011
I realize that I'm 6 years too late, but I just want to say that this post assisted me to solve the exact same problem. I only wish that I have found this earlier (2 days ago).

Cheers JohnnyC
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RowCommand: accessing ObjectDataSource from inside gridview inside a repeater? HockeyFan ASP .Net 1 07-04-2007 05:49 AM
get value from a grid textbox which is inside a repeater tc02435 ASP .Net 0 06-12-2007 12:34 PM
repeater inside a repeater problem. uncensored ASP .Net 0 10-25-2006 06:10 PM
Repeater inside a Repeater Microsoft ASP .Net Web Controls 0 08-21-2006 09:13 AM
Repeater inside a repeater....how? voidfill3d@yahoo.com ASP .Net 1 08-10-2005 01:58 PM



Advertisments