NullReference Exception - Why?

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
 
C

Cor Ligthert

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
 
J

Jon Skeet [C# MVP]

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top