468,248 Members | 1,534 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,248 developers. It's quick & easy.

Object reference not set to an instance of an object.?? Please Help

Hi,

I get the following error when trying to run a search on my aspx site,
this error only occours if the product im searching for does not
exist. Can anybody explain this please and help me with a solution, i
know its probably simple but im new to the game...Cheers

-----------------------------------------------------------------------

Object reference not set to an instance of an object.

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

Source Error:
Line 63: {
Line 64: strSearchValue = Request.QueryString["sv"];
Line 65: lblSearch.Text = "Your search for <b>'" +
strSearchValue + "'</b> brought back <b>no results</b>" ;
Line 66: }
Line 67:


Stack Trace:
[NullReferenceException: Object reference not set to an instance of an
object.]
woodies.searchResults.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\woodies\searchresults.aspx.cs:6 5
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +750
-----------------------------------------------------------------
And here is the some of the code from the page which is prob relevant:
------------------------------------------------------------------

using System.Web.UI.WebControls;

..
..
..
public class searchResults : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblSearch;

..
..
..

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (Request.ServerVariables["HTTPS"].ToString() !="off")
{siteImages = ConfigurationSettings.AppSettings["SiteImagesSecure"];}

if (Request.QueryString["sv"] != null && Request.QueryString
["sv"].ToString() != "")
{
strSearchValue = Request.QueryString["sv"];
lblSearch.Text = "Your search for <b>'" + strSearchValue + "'</b>
brought back <b>no results</b>" ;
}
Nov 16 '05 #1
4 2434
is your string strSearchValue anywhere instanced?

like:
string strSearchValue;

"

"Frawls" wrote:
Hi,

I get the following error when trying to run a search on my aspx site,
this error only occours if the product im searching for does not
exist. Can anybody explain this please and help me with a solution, i
know its probably simple but im new to the game...Cheers

-----------------------------------------------------------------------

Object reference not set to an instance of an object.

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

Source Error:
Line 63: {
Line 64: strSearchValue = Request.QueryString["sv"];
Line 65: lblSearch.Text = "Your search for <b>'" +
strSearchValue + "'</b> brought back <b>no results</b>" ;
Line 66: }
Line 67:


Stack Trace:
[NullReferenceException: Object reference not set to an instance of an
object.]
woodies.searchResults.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\woodies\searchresults.aspx.cs:6 5
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +750
-----------------------------------------------------------------
And here is the some of the code from the page which is prob relevant:
------------------------------------------------------------------

using System.Web.UI.WebControls;

..
..
..
public class searchResults : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblSearch;

..
..
..

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (Request.ServerVariables["HTTPS"].ToString() !="off")
{siteImages = ConfigurationSettings.AppSettings["SiteImagesSecure"];}

if (Request.QueryString["sv"] != null && Request.QueryString
["sv"].ToString() != "")
{
strSearchValue = Request.QueryString["sv"];
lblSearch.Text = "Your search for <b>'" + strSearchValue + "'</b>
brought back <b>no results</b>" ;
}

Nov 16 '05 #2
I hate to be picky, but have you actually stepped through your code in an
IDE and evaluated the variables being used? Unlike some other exceptions,
this one is pretty consistent and predictable. The error message itself is
not cryptic.

Step through your code and see what the value is for your variables at the
point where it fails. One of your variables has no value yet you are trying
to use it.
"Frawls" <fr****@gmail.com> wrote in message
news:32**************************@posting.google.c om...
Hi,

I get the following error when trying to run a search on my aspx site,
this error only occours if the product im searching for does not
exist. Can anybody explain this please and help me with a solution, i
know its probably simple but im new to the game...Cheers

-----------------------------------------------------------------------

Object reference not set to an instance of an object.

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

Source Error:
Line 63: {
Line 64: strSearchValue = Request.QueryString["sv"];
Line 65: lblSearch.Text = "Your search for <b>'" +
strSearchValue + "'</b> brought back <b>no results</b>" ;
Line 66: }
Line 67:


Stack Trace:
[NullReferenceException: Object reference not set to an instance of an
object.]
woodies.searchResults.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\woodies\searchresults.aspx.cs:6 5
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +750
-----------------------------------------------------------------
And here is the some of the code from the page which is prob relevant:
------------------------------------------------------------------

using System.Web.UI.WebControls;

.
.
.
public class searchResults : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblSearch;

.
.
.

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (Request.ServerVariables["HTTPS"].ToString() !="off")
{siteImages = ConfigurationSettings.AppSettings["SiteImagesSecure"];}

if (Request.QueryString["sv"] != null && Request.QueryString
["sv"].ToString() != "")
{
strSearchValue = Request.QueryString["sv"];
lblSearch.Text = "Your search for <b>'" + strSearchValue + "'</b>
brought back <b>no results</b>" ;
}

Nov 16 '05 #3
Could it be that your lblSearch (I'm assuming a label control) has not yet
been instantiated? I'm not too familiar with ASP.NET, but is it possible
that the control is created after the Page_Load method is invoked and so you
need to wait until a later point in time to reference the control?

Tyler

"Frawls" <fr****@gmail.com> wrote in message
news:32**************************@posting.google.c om...
Hi,

I get the following error when trying to run a search on my aspx site,
this error only occours if the product im searching for does not
exist. Can anybody explain this please and help me with a solution, i
know its probably simple but im new to the game...Cheers

-----------------------------------------------------------------------

Object reference not set to an instance of an object.

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

Source Error:
Line 63: {
Line 64: strSearchValue = Request.QueryString["sv"];
Line 65: lblSearch.Text = "Your search for <b>'" +
strSearchValue + "'</b> brought back <b>no results</b>" ;
Line 66: }
Line 67:


Stack Trace:
[NullReferenceException: Object reference not set to an instance of an
object.]
woodies.searchResults.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\woodies\searchresults.aspx.cs:6 5
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +750
-----------------------------------------------------------------
And here is the some of the code from the page which is prob relevant:
------------------------------------------------------------------

using System.Web.UI.WebControls;

.
.
.
public class searchResults : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblSearch;

.
.
.

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (Request.ServerVariables["HTTPS"].ToString() !="off")
{siteImages = ConfigurationSettings.AppSettings["SiteImagesSecure"];}

if (Request.QueryString["sv"] != null && Request.QueryString
["sv"].ToString() != "")
{
strSearchValue = Request.QueryString["sv"];
lblSearch.Text = "Your search for <b>'" + strSearchValue + "'</b>
brought back <b>no results</b>" ;
}

Nov 16 '05 #4
Thanks for the advice guys, much appreciated. The problem was that i
did not have an ASP:label with an ID= lblSearch in my search
Results.aspx page. I no longer recieve the error message, however the
page now seems to try to load and reload infinately without displaying
any information.... So more work for me....

Thanks again,
frawls

Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Pkpatel | last post: by
1 post views Thread by Nathan Sokalski | last post: by
23 posts views Thread by Hugh Oxford | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.