Object reference not set to an instance of an object, error message returned from a webcontrol
<p>Please could someone give me an explanation. I have a webform which displays a table and paging. Table and paging are performed by a web controller included in the web form. When I pass the items from web form to web control everything is fine, but when I modify the values in web controll and try to bind them to the repeater I obtain the error. </p>

<p>I have initialezed and the passed value is not null, I know it from debug.</p>

<pre><code>public class Table : System.Web.UI.UserControl, IPageableControl
{
    // PagedDataSource encapsulates the properties needed to enable paging for the control
    PagedDataSource page = new PagedDataSource();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            object o = Object;
            Session["o"] = o;
        }
    }

    public object Target
    {
        get { return m_ItemsRepeater.DataSource; }
        set
        {
            if (value == null)
                return;

            // display the table of items
            m_ItemsRepeater.DataSource = value;  // here I get the error after clicking
            m_ItemsRepeater.DataBind();
        }
    }

    // when I click on next or prev another controller is called which passes a value to Page
    public void Page(int i)
    {

        // if i == 1 go to next page if -1 to prev page
        if (i == 1)
            CurrentPage += CurrentPage;
        else
        {
            CurrentPage -= CurrentPage;                
        }

        SetPage();
    }

    public void SetPage()
    {
        object oo = (object)System.Web.HttpContext.Current.Session["o"];

        List&lt;USER&gt; u = (List&lt;USER&gt;)oo;

        // number of items per page
        int iPageSize = 5;
        // total items (=&gt; total number of items)
        int total_number_items = u.Count;

        // current page ranges from 0 to max_number_pages-1
        int iTotalPages = (int)Math.Ceiling(((double)total_number_items) / iPageSize);

        // Indicate that the data should be paged              
        page.AllowPaging = true;
        // Set the number of items you wish to display per page
        page.PageSize = iPageSize;

        // number of already displayed items
        int index = CurrentPage * iPageSize;

        // select items to display in the current page. Check if out of range
        if (index + iPageSize &lt; total_number_items)
            page.DataSource = u.GetRange(index, iPageSize).ToList();
        else
            page.DataSource = u.GetRange(index, total_number_items - index).ToList();

        // display items in the pages
        Target = page;

    }

    object s;
    public object Object
    {
        get { return s; }
        set { s = value; }
    }

    public int CurrentPage
    {
        get
        {
            object obj = this.ViewState["CurrentPage"];

            if (obj == null)
            {
                return 0;
            }
            else
            {
                return (int)obj;
            }
        }
        set
        {
            this.ViewState["CurrentPage"] = value;
        }
    }

}

// Web form

public class Items
{
    PagedDataSource page = new PagedDataSource();
    // number of items per page
    int iPageSize = 5;
    int total_number_items;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            // Load the items
            LoadItems();
        }
        else
        {
            // load session using paging from webcontrol
            List&lt;USER&gt; items = db.Get();
            m_Table.Object = items;
        }
    }

    /// &lt;summary&gt;
    /// Load items and display in table.
    /// &lt;/summary&gt;
    private void LoadItems()
    {
        // get list items
        List&lt;USER&gt; items = db.Get();


        DataBind(items, CurrentPage);
    }

    /// &lt;summary&gt;
    /// Enable paging.
    /// &lt;/summary&gt;
    private void DataBind(List&lt;USER&gt; items, int current_page)
    {
        // Indicate that the data should be paged
        page.AllowPaging = true;
        // Set the number of items you wish to display per page
        page.PageSize = iPageSize;

        // number of total pages
        int iTotalPages = ((items.Count + iPageSize - 1) / iPageSize);
        // number of already displayed items
        int index = CurrentPage * iPageSize;

        // select items to display in the current page. Check if out of range
        if (index + iPageSize &lt; items.Count)
            page.DataSource = items.GetRange(index, iPageSize).ToList();
        else
            page.DataSource = items.GetRange(index, items.Count - index).ToList();

        // display items in the pages
        m_Table.Target = page;

    }

    // Called when cursor Previous is clicked.
    protected void lnkPrevious_Click(object sender, EventArgs e)
    {
        // Set viewstate variable to the previous page
        CurrentPage -= 1;
        LoadSupporters();
    }

    // Called when cursor Next is clicked.
    protected void lnkNext_Click(object sender, EventArgs e)
    {
        // Set viewstate variable to the next page
        CurrentPage += 1;
        LoadSupporters();
    }
    public int CurrentPage
    {
        get
        {
            object obj = this.ViewState["CurrentPage"];

            if (obj == null)
            {
                return 0;
            }
            else
            {
                return (int)obj;
            }
        }
        set
        {
            this.ViewState["CurrentPage"] = value;
        }
    }



}
</code></pre>
