Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 540631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:15:36+00:00 2026-05-13T10:15:36+00:00

I know I’ve done something like this before, but I have no idea why

  • 0

I know I’ve done something like this before, but I have no idea why it isn’t working now. I have a ListView with some textboxes. I want to read the text out of those boxes when I click a button (linkbutton, whatever).

        <asp:ListView runat="server" ID="lv_bar" EnableViewState="true">
            <LayoutTemplate>
                <table>
                    <tr>
                        <th>Foo</th>
                    </tr>
                    <tr runat="server" id="itemPlaceholder"></tr>
                </table>
            </LayoutTemplate>
            <ItemTemplate>
                <tr>
                    <td><asp:LinkButton ID="lb_delete" CausesValidation="false" runat="server" Text="Del" /></td>
                    <td><asp:TextBox id="txt_foo" runat="server" /></td>
                </tr>
            </ItemTemplate>
        </asp:ListView>
        <asp:LinkButton ID="lb_add" CausesValidation="false" runat="server" Text="Add" />

And then here’s the relevant code-behind stuff:

protected void Page_Load(object sender, EventArgs e)
{
    lb_chapter_add.Click += lb_chapter_add_Click;

    if (!IsPostBack)
    {
            lv_chapters.DataSource = new List<Foo>() { new Foo() { Name = "harbl"} };
            lv_chapters.DataBind();
        }
    }

void lb_add_Click(object sender, EventArgs e)
{
    foreach (ListViewDataItem item in lv_bar.Items)
    {
        var txt_foo = (TextBox)item.FindControl("txt_foo");
        Response.Write("foo: " + txt_foo.Text);
    }
    Response.Write("<br />the end");
    Response.End();
}

But what I see when I enter some text into txt_foo and click lb_add is just “the end”. What am I doing wrong here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T10:15:37+00:00Added an answer on May 13, 2026 at 10:15 am

    The problem it that you are using a a non persistent object as DataSource.

    Due to clicking the button, you generate a postback and lv_chapters does not contain any items. Set a breakpoint in the line where the foreach is and you will see that lv_chapters.Items in null, or that it’s Count property returns 0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

know nothing about php, but I have this script that reads a folder and
Know of any good libraries for this? I did some searches and didn't come
Know this might be rather basic, but I been trying to figure out how
Does anyone know how can I replace this 2 symbol below from the string
I have just tried to save a simple *.rtf file with some websites and
Know of an OCAML/CAML IDE? Especially one that runs on Linux?
Know of a way to mock %[]? I'm writing tests for code that makes
Know if it's possible to access the iPhone compass in Safari using JavaScript? I
I know in certain circumstances, such as long running processes, it is important to
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.