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

  • Home
  • SEARCH
  • 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 6800807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:00:53+00:00 2026-05-26T19:00:53+00:00

Source First: Default.aspx: <%@ Page Language=C# AutoEventWireup=true CodeBehind=Default.aspx.cs Inherits=WebApplication2.Default %> <!DOCTYPE html PUBLIC -//W3C//DTD

  • 0

Source First:

Default.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication2.Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Repeater ID="Bars" runat="server">
            <ItemTemplate>
                <div>
                    <asp:TextBox ID="Name" Text='<%# Eval("Name") %>' runat="server" AutoPostBack="true" />
                    <asp:TextBox ID="Description" Text='<%# Eval("Description") %>' runat="server" AutoPostBack="true" />
                </div>
            </ItemTemplate>
        </asp:Repeater>
        <asp:Button ID="AddBar" Text="Add Bar" runat="server" onclick="AddBar_Click" />
    </div>
    </form>
</body>
</html>

Default.aspx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication2
{
    public class Foo
    {
        public string Widget { get; set; }
        public string Cog { get; set; }
        public List<Bar> Bars { get; set; }
    }

    public class Bar
    {
        public string Name { get; set; }
        public string Description { get; set; }
    }

    public partial class Default : System.Web.UI.Page
    {
        public Foo Foo
        {
            get
            {
                var retval = Session["Foo"];
                if (retval == null)
                {
                    retval = new Foo();
                    Session["Foo"] = retval;
                }
                return retval == null ? new Foo() : (Foo)retval;
            }
            set
            {
                Session["Foo"] = value;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var f = new Foo() { Bars = new List<Bar>(), Cog = "Cog one", Widget = "Widget Master" };
                f.Bars.Add(new Bar() { Name = "Bar one", Description = "hello." });
                Foo = f;
                Bind();
            }
        }

        protected void Bars_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item != null && e.Item.DataItem != null)
            {
                var b = e.Item.DataItem as Bar;
                var Name = e.Item.FindControl("Name") as TextBox;
                var Description = e.Item.FindControl("Description") as TextBox;
                Name.TextChanged += new EventHandler(Name_TextChanged);
            }
        }

        protected void Name_TextChanged(object sender, EventArgs e)
        {
            var Name = sender as TextBox;
            var listItem = Name.Parent as RepeaterItem;
            var f = Foo;
            var b = f.Bars[listItem.ItemIndex];
            b.Name = Name.Text;
            Foo = f;
            Bind();
        }

        protected void AddBar_Click(object sender, EventArgs e)
        {
            var f = Foo;
            f.Bars.Add(new Bar());
            Foo = f;
            Bind();
        }

        private void Bind()
        {
            Bars.ItemDataBound += new RepeaterItemEventHandler(Bars_ItemDataBound);
            Bars.DataSource = Foo.Bars;
            Bars.DataBind();
        }
    }
}

Now, I haven’t used databinding in years but so I thought I’d refresh my memory, but I can’t get this to work. When I start the app, I see one entry with the values I expect. If I click add, new values show up and the existing value is preserved.

Here is the problem: When I change the value in the Name textbox, I can see the page refresh, but my Name_TextChanged event doesn’t break. Since it doesn’t fire, the value goes back to what it was before.

  • 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-26T19:00:54+00:00Added an answer on May 26, 2026 at 7:00 pm

    Attach OnTextChanged event in aspx. The following codes work.

    protected void Bars_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item != null && e.Item.DataItem != null)
        {
            var b = e.Item.DataItem as Bar;
            var Name = e.Item.FindControl("Name") as TextBox;
            var Description = e.Item.FindControl("Description") as TextBox;
            // Commented
            // Name.TextChanged += new EventHandler(Name_TextChanged);
        }
    }
    
    <asp:TextBox ID="Name" Text='<%# Eval("Name") %>' runat="server" 
    AutoPostBack="true" OnTextChanged="Name_TextChanged" /> 
    
    <asp:TextBox ID="Description" Text='<%# Eval("Description") %>' 
    runat="server" AutoPostBack="true" OnTextChanged="Name_TextChanged" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

dict methods dict.keys() , dict.items() and dict.values() return views instead of lists. Source First
When I installed perl from the source the first nice surprise was that without
This is the first time I'm creating an open-source project, and I've decided (based
First the requirements: By management requirements, I can't use open source code. I need
I'm trying to contribute to open source software for the first time, but I'm
the row source for a listbox looks like this: SELECT users.id, users.first, users.last, chavrusas.luser_type
I just started my first Mercurial project. I did a 'cd' into my source
I'm browsing source codes from two applications sharing one queue using MSMQ. The first
I am trying to add my first unit test to an existing Open Source
Just recently I dove into the VideoLAN open source project. This was my first

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.