NullReference Exception - Why?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • wallaceoc

    #1

    NullReference Exception - Why?

    I keep getting the following error with the code below:


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


    Caused by this line:

    this.basicSearc h.OnSomethingHa ppened += new
    System.EventHan dler(this.ShowR esult);


    Here is some of my code:

    CODE
    private void ShowResult(obje ct sender, System.EventArg s e)
    {
    this.results.se archData = ((BasicSearch)s ender).searchDa ta;
    PlaceHolder1.Co ntrols.Clear();
    resultsCtrl = LoadControl("re sults.asxc");
    PlaceHolder1.Co ntrols.Add(resu ltsCtrl);
    Response.Write( "NOT HAPPENING");
    }


    private void InitializeCompo nent()
    {
    this.Load += new System.EventHan dler(this.Page_ Load);
    this.basicSearc h.OnSomethingHa ppened += new
    System.EventHan dler(this.ShowR esult);

    }


    OnSomethingHapp enened is an event declared in my BasicSearch usercontrol page.

    Any ideas whats wrong?


    Regards,

    Wallace
  • Cor Ligthert

    #2
    Re: NullReference Exception - Why?

    Wallaceoc,

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

    microsoft.publi c.dotnet.langua ges.csharp

    Cor


    Comment

    • Jon Skeet [C# MVP]

      #3
      Re: NullReference Exception - Why?

      wallaceoc <wallaceoc@disc ussions.microso ft.com> wrote:[color=blue]
      > I keep getting the following error with the code below:[/color]
      [color=blue]
      > Exception Details: System.NullRefe renceException: Object reference not set
      > to an instance of an object.
      >
      > Caused by this line:
      >
      > this.basicSearc h.OnSomethingHa ppened += new
      > System.EventHan dler(this.ShowR esult);[/color]

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

      --
      Jon Skeet - <skeet@pobox.co m>
      Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

      If replying to the group, please do not mail me too

      Comment

      Working...