Solved

Object reference not set to an instance of an object. !ISPOSTBACK

Posted on 2009-07-16
3
389 Views
Last Modified: 2013-12-17
Hello,

I am getting the Object Reference message but I am confused because I did create an instance of the base class in the calling program " CheckProgramAccess CPA = new CheckProgramAccess()"

The error is being thrown within the .DLL at this statement:
"string TrackId = HttpContext.Current.Request.QueryString["track"].Substring(0,8) ;"

The Part 2 of the code is in a .dll which I am not allowed to change.  So my question is - two fold:
1). Why is this error happening since I did create an instance as demonstrated by CPA....and
2). How do I resolve this within my Part 1 code sniplet?

Thank you!
Part#1:

 protected void Page_Load(object sender, EventArgs e)
 

        {

        if (!IsPostBack)

            {

            CheckProgramAccess CPA = new CheckProgramAccess();
 

            if (!CPA.Authorized())

                {

                Response.Redirect("/asp/home.asp");

                }

            else

                {
 

                }

            }

=========

Part# 2:
 

public class CheckProgramAccess

	{

		public CheckProgramAccess()

		{

			//

			// TODO: Add constructor logic here

			//

		}
 

		public bool Authorized()

		{

			bool Authenticated = true;

			bool RtnCde = false ;

			string UpId = "" ;

			string TimeOut = "" ;

			string LogTime = "" ;
 

			try

			{

				string TrackId = HttpContext.Current.Request.QueryString["track"].Substring(0,8) ;

				string Program =  HttpContext.Current.Request.QueryString["program"].ToString() ;

	}

			catch(Exception ex)

			{

				string msg = ex.Message.ToString();

				Authenticated = false ;

			}

			return Authenticated;

		}

Open in new window

0
Comment
Question by:Muaadeeb
3 Comments
 
LVL 12

Accepted Solution

by:
GuitarRich earned 175 total points
ID: 24870383
The error is probably occuring because the Request.QueryString doesn't contain a "track" entry.
You should check for this before assigning it to a variable in the dll.
If you can't change the DLL - then check for it before the call to the DLL e.g

 protected void Page_Load(object sender, EventArgs e)

 

        {

        if (!IsPostBack)

            {

            if (Request.QueryString["track"] != null)

            {

                CheckProgramAccess CPA = new CheckProgramAccess();

 

                if (!CPA.Authorized())

                {

                    Response.Redirect("/asp/home.asp");

                }

                else

                {

 

                }

            }

        }

Open in new window

0
 
LVL 41

Assisted Solution

by:guru_sami
guru_sami earned 75 total points
ID: 24870413
looks you Request.QueryString["track"] is null...
When you are accessing you page ...are you passing queryString parameter track and program in the url....
What is the url of the Page?
0
 

Author Comment

by:Muaadeeb
ID: 24872218
Thanks guys you were right.   The query string was null and as a result the .DLL code had no idea what it was supposed to be referencing.


Thank you!

0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now