get value from asp:textbox inside Repeater

Discussion in 'ASP .Net' started by datakix@gmail.com, Aug 17, 2005.

  1. Guest

    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
    , Aug 17, 2005
    #1
    1. Advertising

  2. sanda

    Joined:
    May 16, 2011
    Messages:
    1
    thanks OP

    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.
    sanda, May 16, 2011
    #2
    1. Advertising

  3. JohnnyC

    Joined:
    Aug 8, 2011
    Messages:
    1
    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
    JohnnyC, Aug 8, 2011
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    7,014
    Karl Seguin
    Aug 10, 2005
  2. uncensored
    Replies:
    0
    Views:
    801
    uncensored
    Oct 25, 2006
  3. tc02435
    Replies:
    0
    Views:
    466
    tc02435
    Jun 12, 2007
  4. tc02435
    Replies:
    0
    Views:
    404
    tc02435
    Jun 12, 2007
  5. Microsoft

    Repeater inside a Repeater

    Microsoft, Aug 21, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    197
    Microsoft
    Aug 21, 2006
Loading...

Share This Page