469,646 Members | 1,334 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

System.Web.UI.Page derivative...

I have a 'BasePage' (BasePage.cs) derived from System.Web.UI.Page that all
my pages inherit from. I need to set some properties (either in the OnInit
or constructor) based on a potential Request.Cookie or a name/value pair in
Request.QueryString.
But I am getting a
'System.NullReferenceException: Object reference not set to an instance of
an object.'
error when I try to view any aspx derived from this BasePage.
I am using HttpContext.Current.Request.Cookies as well as for the
QueryString but still get this error.
Any ideas!?

Thank you.
Nov 18 '05 #1
4 4932
Are you using Request.QueryString.Get("name").Value?

-Brian K. Williams

"Terry Mulvany" <te****@mcelroyla.com> wrote in message
news:Oi**************@TK2MSFTNGP09.phx.gbl...
I have a 'BasePage' (BasePage.cs) derived from System.Web.UI.Page that all
my pages inherit from. I need to set some properties (either in the OnInit or constructor) based on a potential Request.Cookie or a name/value pair in Request.QueryString.
But I am getting a
'System.NullReferenceException: Object reference not set to an instance of
an object.'
error when I try to view any aspx derived from this BasePage.
I am using HttpContext.Current.Request.Cookies as well as for the
QueryString but still get this error.
Any ideas!?

Thank you.

Nov 18 '05 #2
What is the line of code that is throwing this exception? There is an object
reference in that line that is not initialized or is null for some reason.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Terry Mulvany" <te****@mcelroyla.com> wrote in message
news:Oi**************@TK2MSFTNGP09.phx.gbl...
I have a 'BasePage' (BasePage.cs) derived from System.Web.UI.Page that all
my pages inherit from. I need to set some properties (either in the OnInit or constructor) based on a potential Request.Cookie or a name/value pair in Request.QueryString.
But I am getting a
'System.NullReferenceException: Object reference not set to an instance of
an object.'
error when I try to view any aspx derived from this BasePage.
I am using HttpContext.Current.Request.Cookies as well as for the
QueryString but still get this error.
Any ideas!?

Thank you.

Nov 18 '05 #3
To be more specific...
namespace CIBWeb
{
public class BasePage : System.Web.UI.Page
{
public BasePage()
{
}

protected override void OnInit(EventArgs e)
{
if (
HttpContext.Current.Request.Cookies["source_code"].Value.ToString() !=
string.Empty )
{
...
}
...
}
}
}

YIELDS THIS ERROR ...
Server Error in '/CIBWeb' Application.
----------------------------------------------------------------------------
----

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

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

Source Error:
Line 64: // no other source code overrides it. ex: user clicks url in
email (email campaign) and then once on the site clicks on a ad banner
(which has
Line 65: // it's own source code), the first source code should still be
the one used
Line 66: if (
HttpContext.Current.Request.Cookies["source_code"].Value.ToString() !=
string.Empty )
Line 67: {
Line 68: SourceCode =
HttpContext.Current.Request.Cookies["source_code"].Value.ToString();
Source File: c:\inetpub\wwwroot\cibweb\src\basepage.cs Line: 66

Stack Trace:
[NullReferenceException: Object reference not set to an instance of an
object.]
CIBWeb.BasePage.OnInit(EventArgs e) in
c:\inetpub\wwwroot\cibweb\src\basepage.cs:66
CIBWeb.HealthWellness._Default.OnInit(EventArgs e) in
c:\inetpub\wwwroot\CIBWeb\HealthWellness\Default.a spx.cs:74
System.Web.UI.Control.InitRecursive(Control namingContainer)
System.Web.UI.Page.ProcessRequestMain()

ANY IDEAS?
"Kevin Spencer" <ke***@takempis.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
What is the line of code that is throwing this exception? There is an object reference in that line that is not initialized or is null for some reason.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Terry Mulvany" <te****@mcelroyla.com> wrote in message
news:Oi**************@TK2MSFTNGP09.phx.gbl...
I have a 'BasePage' (BasePage.cs) derived from System.Web.UI.Page that all my pages inherit from. I need to set some properties (either in the

OnInit
or constructor) based on a potential Request.Cookie or a name/value pair

in
Request.QueryString.
But I am getting a
'System.NullReferenceException: Object reference not set to an instance of an object.'
error when I try to view any aspx derived from this BasePage.
I am using HttpContext.Current.Request.Cookies as well as for the
QueryString but still get this error.
Any ideas!?

Thank you.


Nov 18 '05 #4
To be more specific...
namespace CIBWeb
{
public class BasePage : System.Web.UI.Page
{
public BasePage()
{
}

protected override void OnInit(EventArgs e)
{
if (
HttpContext.Current.Request.Cookies["source_code"].Value.ToString() !=
string.Empty )
{
...
}
...
}
}
}

YIELDS THIS ERROR ...
Server Error in '/CIBWeb' Application.
----------------------------------------------------------------------------
----

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

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

Source Error:
Line 64: // no other source code overrides it. ex: user clicks url in
email (email campaign) and then once on the site clicks on a ad banner
(which has
Line 65: // it's own source code), the first source code should still be
the one used
Line 66: if (
HttpContext.Current.Request.Cookies["source_code"].Value.ToString() !=
string.Empty )
Line 67: {
Line 68: SourceCode =
HttpContext.Current.Request.Cookies["source_code"].Value.ToString();
Source File: c:\inetpub\wwwroot\cibweb\src\basepage.cs Line: 66

Stack Trace:
[NullReferenceException: Object reference not set to an instance of an
object.]
CIBWeb.BasePage.OnInit(EventArgs e) in
c:\inetpub\wwwroot\cibweb\src\basepage.cs:66
CIBWeb.HealthWellness._Default.OnInit(EventArgs e) in
c:\inetpub\wwwroot\CIBWeb\HealthWellness\Default.a spx.cs:74
System.Web.UI.Control.InitRecursive(Control namingContainer)
System.Web.UI.Page.ProcessRequestMain()

ANY IDEAS?
"Brian K. Williams" <wi*******@millenia.com> wrote in message
news:uz**************@TK2MSFTNGP12.phx.gbl...
Are you using Request.QueryString.Get("name").Value?

-Brian K. Williams

"Terry Mulvany" <te****@mcelroyla.com> wrote in message
news:Oi**************@TK2MSFTNGP09.phx.gbl...
I have a 'BasePage' (BasePage.cs) derived from System.Web.UI.Page that all my pages inherit from. I need to set some properties (either in the

OnInit
or constructor) based on a potential Request.Cookie or a name/value pair

in
Request.QueryString.
But I am getting a
'System.NullReferenceException: Object reference not set to an instance of an object.'
error when I try to view any aspx derived from this BasePage.
I am using HttpContext.Current.Request.Cookies as well as for the
QueryString but still get this error.
Any ideas!?

Thank you.


Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by DDCane | last post: by
3 posts views Thread by jlynx23 | last post: by
6 posts views Thread by knielsen73 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.