Monday, March 26, 2012

Session variable concatenation

Hi,
I think I might have misunderstood the implementation of this concept in ASP.NET/C#.
I have a string array called WinArr[]. I would like to concat the contents of three session variables and put the result into WinArr[0]; I have tried:

WinArr[0] =this.Session["WinBoxesArr0"].ToString() +this.Session["WinBoxesArr1"].ToString() +this.Session["WinBoxesArr2"].ToString();

but I get the following error (with or without using this. ) :

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 70: {Line 71:Line 72: WinArr[0] = this.Session["WinBoxesArr0"].ToString() + this.Session["WinBoxesArr1"].ToString() + this.Session["WinBoxesArr2"].ToString();Line 73:


Any help appreciated...

E.Have you properly defined the array?

string[] WinArr =newstring[1];


Have you instantiated theWinArr? Also, are you sure that each Session variable has been set?

Thanks! I forgot to set the variables...
This looks like the same problems you brought up inhttp://forums.asp.net/1079383/ShowPost.aspx with Application replaced by Session.
Sort of, but not really. The original problem was with arrays.

And this problem looks like it's with arrays also. Try this:
string [] WinArr = new string [1];

WinArr[0] = string.Empty;

if ( this.Session["WinBoxesArr0"] != null)
WinArr[0] += this.Session["WinBoxesArr0"].ToString();
if ( this.Session["WinBoxesArr1"] != null)
WinArr[0] += this.Session["WinBoxesArr0"].ToString();
if ( this.Session["WinBoxesArr2"] != null)
WinArr[0] += this.Session["WinBoxesArr0"].ToString();
NC...

0 comments:

Post a Comment