none
Object reference not set to an instance of an object. RRS feed

  • Question

  • Object reference not set to an instance of an object.

    Calendar

    Rohit= new Calendar();

    TextBox TextBox1 = new TextBox();

    Rohit = (

    Calendar)(PreviousPage.FindControl("Rohit"));

    TextBox1 = (

    TextBox)(PreviousPage.FindControl("TextBox1"));

    Label1.Text =

    "Hi" + TextBox1.Text + ", here is the output of the Cross Page post Back Button: " + Rohit.SelectedDate.ToString();

    }

    }

    Sunday, September 23, 2012 10:17 PM

Answers

  • Object reference not set to an instance of an object.

    Calendar Rohit = new Calendar();
    Rohit.ID = "Rohit";
    
    TextBox TextBox1 = new TextBox();
    TextBox1.ID = "TextBox1";

    Rohit = (

    Calendar)(PreviousPage.FindControl("Rohit"));

    TextBox1 = (

    TextBox)(PreviousPage.FindControl("TextBox1"));

    Label1.Text =

    "Hi"+ TextBox1.Text + ", here is the output of the Cross Page post Back Button: "+ Rohit.SelectedDate.ToString();

    }

    }

    Are you sure that Rohit and TextBox1 are actually the ID's of the controls on the previous page - you have not explicitly assigned these as the ID's in your code.  Sometimes, depending on where .NET controls sit within other controls in the hierarchy, ASP.NET will assign a prefix to the name of the control as it's ID.

    You need to check this, or otherwise actually assign the ID to the controls like so -

    Calendar Rohit = new Calendar();
    Rohit.ID = "Rohit";
    
    TextBox TextBox1 = new TextBox();
    TextBox1.ID = "TextBox1";


    • Edited by WombleNumber1 Monday, September 24, 2012 10:33 AM
    • Proposed as answer by WombleNumber1 Monday, September 24, 2012 10:33 AM
    • Marked as answer by Alexander Sun Tuesday, October 9, 2012 8:55 AM
    Monday, September 24, 2012 10:32 AM

All replies

  • For Asp.net realted question please use http://forums.asp.net/. There you will get prompt response from asp.net experts

    Lingaraj Mishra

    Monday, September 24, 2012 9:00 AM
  • Object reference not set to an instance of an object.

    Calendar Rohit = new Calendar();
    Rohit.ID = "Rohit";
    
    TextBox TextBox1 = new TextBox();
    TextBox1.ID = "TextBox1";

    Rohit = (

    Calendar)(PreviousPage.FindControl("Rohit"));

    TextBox1 = (

    TextBox)(PreviousPage.FindControl("TextBox1"));

    Label1.Text =

    "Hi"+ TextBox1.Text + ", here is the output of the Cross Page post Back Button: "+ Rohit.SelectedDate.ToString();

    }

    }

    Are you sure that Rohit and TextBox1 are actually the ID's of the controls on the previous page - you have not explicitly assigned these as the ID's in your code.  Sometimes, depending on where .NET controls sit within other controls in the hierarchy, ASP.NET will assign a prefix to the name of the control as it's ID.

    You need to check this, or otherwise actually assign the ID to the controls like so -

    Calendar Rohit = new Calendar();
    Rohit.ID = "Rohit";
    
    TextBox TextBox1 = new TextBox();
    TextBox1.ID = "TextBox1";


    • Edited by WombleNumber1 Monday, September 24, 2012 10:33 AM
    • Proposed as answer by WombleNumber1 Monday, September 24, 2012 10:33 AM
    • Marked as answer by Alexander Sun Tuesday, October 9, 2012 8:55 AM
    Monday, September 24, 2012 10:32 AM