Using C#, how can I update listbox Items from another class?

Hy,

In my project asp.net (c#), I am using threading to process some messages. I have a display page that contain a listbox with all the actions that are taken in processing the message. And a class where I am processing the message.

Default.aspx:

        protected void Page_Load(object sender, EventArgs e)
        {
            //starts the thread and call the method from Process.cs
        }

        public void SetListItem(string text)
        {
            myListBox.Items.Add(text);
            myListBox.DataBind();
        }

Process.cs

public class Process
{
  public Process()
  {
    Default defaultPage;
    defaultPage.SetListItem("==> Received message!");
  }
}

But the listbox do not show nothing. Does anyone has any ideea where I'm wrong? Thanks.

Jeff

Answers


Remove the databind

 myListBox.DataBind();

You don't need it since you are adding an item to the list collection. If you were setting the DataSource property, you would then have to use it. This is all depending on where in the life-cycle your update is firing as well. It could be that your update is being replaced by code somewhere else in the process as well.

In truth, I would take this out of being a separate thread. Since you need it to be updated before the page submits information to the browser, you either need to keep it in the same thread to make sure it completes, or you're going to need to have some sort of a check at the end of your page executing process to make sure it has finished. It is possible your thread is completing after the page has finished processing.


Need Your Help

AppDomain.CurrentDomain.ProcessExit and cleanup

c# .net events

I have simple application when I need to stop a backround thread using Stop() function before application is closed. The problem is that my Main() function has several exit points (return statement...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.