How to create a complete AJAX Server Control. Part 5.

Posted on Updated on

In the previous post we saw that the Items were disappeared like cowards once we executed a postback. That’s the standard behaviour of the GridView control as well, so don’t worry.

To maintain the Items we have several choices:

  1. The basic implementation is to keep the list in the view state (that’s the implementation in the samples). This will work with no issues but it’s not very configurable
  2. 		List items
    			get { return GetPropertyValue("items", (List)null); }
    			set { SetPropertyValue("items", value); }
  3. A bit more sofisticated solution, and the way GridView works, would be taking into consideration the EnableViewState property and depending on the value, then saving it in the View State or in a member
  4. 		List _items = new List();
    		List items
    				if (EnableViewState)
    					return GetPropertyValue("items", (List)null);
    					return _items;
    				if( value == null)
    					value = new List();
    				if (EnableViewState)
    					SetPropertyValue("items", value);
    					_items = value;

If we run the example now, we can see how all the items are there after the postback and the new ones are added to the list, just as expected. Just remember that the more you add to the ViewState, de bigger the page.

You can download the code here.
Important: I couldn’t upload the file as it was a zip file, so I added the extension jpg. After saving the file, remove the extension and unzip it normally.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s