[Webinar] Streamline your web hosting managementRegister Today


500pts: Context.items not working, can you help?

Posted on 2006-05-29
Medium Priority
Last Modified: 2007-12-19
Hi there,

I wonder if anyone can help. I have just migrated an application from visual studio 2003 to visual studio 2005... It all went well... apart from one thing really...

Each page uses a method to transfer information to a web page that is used for errors i.e.

                        Context.Items[ "error_code" ] = iErrorCode.ToString();
                        Context.Items[ "error_description" ] = ex.Message;
                        Context.Items[ "error_page" ] = this.GetType().Name;
                        Context.Items[ "iduser" ] = "test"

                        Server.Transfer( "error.aspx" );

It appears to function correctly at this point, the user gets transfered to the error page... but this is where it doesn't work... In code... it basically does the following..

            string      strErrorCode            = Context.Items[ "error_code" ].ToString();
But it appears to be erroring on the first line i.e. the line above... gives the following error

{"Object reference not set to an instance of an object."} "NullReferenceException" was  unhandled by user code..

Strange... also the count of Context.Items is 0... i checked it with Intellisense and in the command window...

>? Context.Items.Count

Can anyone help?

Thanks in advance


Question by:ianinspain
  • 4
  • 2
LVL 27

Accepted Solution

Sammy earned 2000 total points
ID: 16782660
change server.transfer line to Server.Transfer( "error.aspx" ,true);
it is false by default

LVL 27

Expert Comment

ID: 16782712
one more thing, in the recieving page you have to cast the viewstate item to a string

string strErrorCode  = ((string)(Context.Items("error_code" )));

if you do a response.write it will output whatever in the error_code from the context item


Author Comment

ID: 16782757
Hi there, thanks... but it didn't help.... although i can understand what you are saying here..

I was watching  my Auto watches... and i have all my context.items there... in fact the complete COUNT is 6
and as soon as it does a       Server.Transfer( "error.aspx", true );

I lose all my context.items ... in fact nothing is preserved....

I was debugging and watched it... fill the context.items and then transfer to a new page ... so i know it went to a new page.. (error.aspx)

Very strange......

Any ideas?

I presume in Vs 2005 something has changed......

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.


Author Comment

ID: 16782768
Hi sammy,

Just saw your other msg... Yes that is currently what happens on the error page... actually its done slightly different... But as i say the context.items seem to clear when it transfers...

This is what is done in the error.aspx but it errros..... but due to the fact that context.items is empty and doesn't exist

string      strErrorCode            = Context.Items[ "error_code" ].ToString();
                  string      strErrorDesc            = Context.Items[ "error_description" ].ToString();
                  string      strErrorPage            = Context.Items[ "error_page" ].ToString();
                  string      strIdUser                  = Context.Items[ "iduser" ].ToString();
LVL 10

Expert Comment

ID: 16782852
Try Like This



Author Comment

ID: 16782908
Yes ... on the errro page .... the context items are lost...

if i do the above.. on the error i get this

>? HttpContext.Current.Items
Count = 0

This is really strange......

Author Comment

ID: 16783131
Wow! i found out the problem ... But im a little confused..

Basically Page_Load was loading twice.... and on the second load it would blank out the context.items

I have to set the AutoEventFireup to false... as it was set to true

So it now works BUT when i create a new page ... it sets the  AutoEventFireup to true and hence i can execute the page_load .. no probs..

Set it to false stops my NEW page from executing page_load ...

What i can't understand is why settting autoeventfireup to false in my errror.aspx page doesn't stop it from launching page_load...

Do you know why?

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…

607 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