System.Web.UI.Page derivative...

Discussion in 'ASP .Net' started by Terry Mulvany, Mar 2, 2004.

  1. 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.
     
    Terry Mulvany, Mar 2, 2004
    #1
    1. Advertising

  2. Are you using Request.QueryString.Get("name").Value?

    -Brian K. Williams

    "Terry Mulvany" <> wrote in message
    news:...
    > 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.
    >
    >
     
    Brian K. Williams, Mar 2, 2004
    #2
    1. Advertising

  3. 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" <> wrote in message
    news:...
    > 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.
    >
    >
     
    Kevin Spencer, Mar 3, 2004
    #3
  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.aspx.cs:74
    System.Web.UI.Control.InitRecursive(Control namingContainer)
    System.Web.UI.Page.ProcessRequestMain()

    ANY IDEAS?
    "Kevin Spencer" <> wrote in message
    news:%...
    > 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" <> wrote in message
    > news:...
    > > 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.
    > >
    > >

    >
    >
     
    Terry Mulvany, Mar 3, 2004
    #4
  5. 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.aspx.cs:74
    System.Web.UI.Control.InitRecursive(Control namingContainer)
    System.Web.UI.Page.ProcessRequestMain()

    ANY IDEAS?
    "Brian K. Williams" <> wrote in message
    news:...
    > Are you using Request.QueryString.Get("name").Value?
    >
    > -Brian K. Williams
    >
    > "Terry Mulvany" <> wrote in message
    > news:...
    > > 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.
    > >
    > >

    >
    >
     
    Terry Mulvany, Mar 3, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Terry Mulvany
    Replies:
    2
    Views:
    2,923
    Terry Mulvany
    Mar 3, 2004
  2. Chuck Chopp
    Replies:
    4
    Views:
    400
    Chuck Chopp
    Aug 25, 2006
  3. xhunga
    Replies:
    3
    Views:
    269
    xhunga
    Mar 10, 2007
  4. xhunga
    Replies:
    0
    Views:
    299
    xhunga
    Mar 10, 2007
  5. xhunga
    Replies:
    0
    Views:
    298
    xhunga
    Mar 16, 2007
Loading...

Share This Page