views:

27

answers:

1

Hi, I need to create a list of dynamically generated entries on the client as the user can control how many entries he needs pressing a + symbol. Functionality in some sense is similar to the "Google Finance Stock Screener" add criteria.

In code I have a model that looks like this:

public class Model
{
    public List<string> DynamicList { get; set; }
}

Now the first time the server may provide an empty list. The user from the web browser now can add using the + symbol editors for the dynamic list elements (in this particular case a TextBox).

Do you know of any way to implement this functionality without resorting to a request a new list to the server (that is through either a postback or an AJAX call) on each addition?

Thanks in advance.

PD: Question left open as community wiki for anyone to improve on the question itself.

+1  A: 

The architecture you should be using implements AJAX calls. It should be something like that:

  1. Page rendered to user. List is empty. User presses + button
  2. If you need to store on your database, or session variable, each single addition, an ajax call is performed every time the + button is pressed. Data is sent to the server, which handles it as you see fit.
  3. If you don't need to store each single addition, you can have simple JS adding items on the page, and a save button at the end, which posts (through ajax or normal submit as you prefer) all the additions to the server.
Matteo Mosca
This really is the only way I can think to implement this. There are two options, but either one works.
drachenstern
Yes the underlying problem is on how to trick the data binder to bind those elements into the list itself. Going AJAX in a sense is some sort of a "postback" (one that doesnt refresh the page, but going to the server anyway). Will rewrite that part on the question.
Red Knight