Object reference not set to an instance of an Object

3 posts, 1 answers
  1. Benjamin
    Benjamin avatar
    11 posts
    Member since:
    Dec 2012

    Posted 15 Jan 2013 Link to this post

    This error pop-up message keeps appearing whenever I enter a text.
    I've tried searching for solutions and examples but I get the "Sorry, we couldn't find the page you're looking for." whenever I click on the "Launch ASP.NET AJAX Demos" link (http://demos.telerik.com/ErrorPageResources/error.aspx?aspxerrorpath=/aspnet-ajax/default.aspx).

    My code is something like this:

    <telerik:RadAutoCompleteBox ID="RadAutoCompleteBox1" runat="server"></telerik:RadAutoCompleteBox>


    protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack) {     
     
                    RadAutoCompleteBox1.DataSource = GetData();
                    RadAutoCompleteBox1.DataTextField = "Item_Desc";
                    RadAutoCompleteBox1.DataValueField = "Item_Code";
     
                }
            }
     
    private static DataTable GetData()
            {
                DataTable dt = new DataTable();
                //Set the datafield name
                DataColumn cl = new DataColumn("status");
                dt.Columns.Add(cl);
                cl = new DataColumn("Item_Code");
                dt.Columns.Add(cl);
                cl = new DataColumn("Item_Desc");
                dt.Columns.Add(cl);
                cl = new DataColumn("Vendor_Name");
                dt.Columns.Add(cl);
                cl = new DataColumn("Uom");
                dt.Columns.Add(cl);
                cl = new DataColumn("Moq");
                dt.Columns.Add(cl);
                cl = new DataColumn("Qty");
                dt.Columns.Add(cl);
                cl = new DataColumn("Cur");
                dt.Columns.Add(cl);
                cl = new DataColumn("Price");
                dt.Columns.Add(cl);
                cl = new DataColumn("Total");
                dt.Columns.Add(cl);
                cl = new DataColumn("Type");
                dt.Columns.Add(cl);
     
     
                //Set the static data for row 1
                DataRow dr = dt.NewRow();
                dr[0] = "";
                dr[1] = "07-11-017";
                dr[2] = "PAPER PUNCHER (3 HOLES)";
                dr[3] = "Internal";
                dr[4] = "PC";
                dr[5] = "1";
                dr[6] = "1";
                dr[7] = "SGD";
                dr[8] = "130.00";
                dr[9] = "130.00";
                dr[10] = "NS";
                dt.Rows.Add(dr);
     
     
                //Set the static data for row 2
                dr = dt.NewRow();
                dr[0] = "";
                dr[1] = "07-09-069";
                dr[2] = "BINDING STRIPS A4 (MULTI-COLOUR) (LOT OF 100/50PC) ";
                dr[3] = "Internal";
                dr[4] = "PC";
                dr[5] = "1";
                dr[6] = "1";
                dr[7] = "SGD";
                dr[8] = "60.00";
                dr[9] = "60.00";
                dr[10] = "NS";
                dt.Rows.Add(dr);
     
                //Set the static data for row 3
                dr = dt.NewRow();
                dr[0] = "";
                dr[1] = "01-38-002";
                dr[2] = "LAMINATING MACHINE A4, LMA400";
                dr[3] = "Internal";
                dr[4] = "PC";
                dr[5] = "1";
                dr[6] = "1";
                dr[7] = "SGD";
                dr[8] = "160.00";
                dr[9] = "160.00";
                dr[10] = "NS";
                dt.Rows.Add(dr);
     
                //Set the static data for row 4
                dr = dt.NewRow();
                dr[0] = "";
                dr[1] = "99-09-901";
                dr[2] = "BOLTED CONNECTOR";
                dr[3] = "Internal";
                dr[4] = "PC";
                dr[5] = "10";
                dr[6] = "10";
                dr[7] = "SGD";
                dr[8] = "1.50";
                dr[9] = "15.00";
                dr[10] = "ST";
                dt.Rows.Add(dr);
     
                //Set the static data for row 5
                dr = dt.NewRow();
                dr[0] = "";
                dr[1] = "99-07-905";
                dr[2] = "GUY STRAIN INSULATOR";
                dr[3] = "Internal";
                dr[4] = "PC";
                dr[5] = "100";
                dr[6] = "100";
                dr[7] = "SGD";
                dr[8] = "1.00";
                dr[9] = "100.00";
                dr[10] = "ST";
                dt.Rows.Add(dr);
     
                //Set the static data for row 6
                dr = dt.NewRow();
                dr[0] = "";
                dr[1] = "99-01-505";
                dr[2] = "HOT LINE CLAMP";
                dr[3] = "Internal";
                dr[4] = "PC";
                dr[5] = "500";
                dr[6] = "500";
                dr[7] = "SGD";
                dr[8] = "2.00";
                dr[9] = "1000.00";
                dr[10] = "ST";
                dt.Rows.Add(dr);
     
                return dt;
            }
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 15 Jan 2013 Link to this post

    Hi,

    The autocompletetextbox control triggers page load every time you type on the control - even if you wrap the control with an update panel. So,  you must bind the datasource in the Page_Load method(without !IsPostBack) in order to solve this problem as follows.

    C#:
    protected void Page_Load(object sender, EventArgs e)
    {
            RadAutoCompleteBox1.DataSource = GetData();
            RadAutoCompleteBox1.DataTextField = "Item_Desc";
            RadAutoCompleteBox1.DataValueField = "Item_Code";
    }

    Hope this helps.

    Regards,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Benjamin
    Benjamin avatar
    11 posts
    Member since:
    Dec 2012

    Posted 15 Jan 2013 Link to this post

    It solved my issue! Thanks!
Back to Top