NullReference Exception - Why?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I keep getting the following error with the code below:


Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.


Caused by this line:

this.basicSearch.OnSomethingHappened += new
System.EventHandler(this.ShowResult);


Here is some of my code:

CODE
private void ShowResult(object sender, System.EventArgs e)
{
this.results.searchData = ((BasicSearch)sender).searchData;
PlaceHolder1.Controls.Clear();
resultsCtrl = LoadControl("results.asxc");
PlaceHolder1.Controls.Add(resultsCtrl);
Response.Write("NOT HAPPENING");
}


private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
this.basicSearch.OnSomethingHappened += new
System.EventHandler(this.ShowResult);

}


OnSomethingHappenened is an event declared in my BasicSearch usercontrol page.

Any ideas whats wrong?


Regards,

Wallace
 
Wallaceoc,

Although in this newsgroup are persons active who know a lot of C# is the
better place for C# related questions

microsoft.public.dotnet.languages.csharp

Cor
 
wallaceoc said:
I keep getting the following error with the code below:
Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Caused by this line:

this.basicSearch.OnSomethingHappened += new
System.EventHandler(this.ShowResult);

That suggests that basicSearch is null. What have you done to make sure
it's not null?
 
Back
Top