In this section we will explain in detail the solution we
have implemented to solve the problem.
We have added two Hidden Fields that will be injected by the
new control developed.
The first Hidden Field is named with this convention:
ListBoxID + “_ADDED”
The above field will be used to hold any item that has been
added to the ListBox on the client side. Suppose you have added the item with:
Text = “First Item”
Value = “1”
A new item will be added to the Hidden Field in the form of:
Text|Value
For instance, an item will be added as follows:
First Item|1
Any additional item will be added to the Hidden Field.
Item1|Value1,Item2|Value2
The format of how the items are added to the Hidden Field is
very critical. Since, as you will see later on, we are going to get the value
of the above Hidden Field, split it based on the “,” and then each single item
will be added as a new ListItem into the ListBox.
The second Hidden Field used is named with this convention:
ListBoxID + “_REMOVED”
The above Hidden Field will hold the values of all the items
that have been removed from the ListBox. Later on we will see that on the
server, those values will be selected in the ListBox and removed, thus
reflecting the behavior and changes done on the client side.
In addition to the above mentioned section of the solution,
we will be implementing the IPostBackDataHandler, where two methods will be
reworked mainly the LoadPostData and RaisePostDataChangedEvent. More on the
implementation of this interface will be discussed shortly in this article.