When I use this code it actually adds a number to the end of the current session number instead of adding another number to the current one on the label. I'm using this counter every time a user hit the save button.
My session variables are declared in the global.aspx. Like I said it works just fine in vb, but it does not in C.
Leo D.
Member
3 Points
30 Posts
C# using Session
Jul 29, 2012 12:42 AM|LINK
I'm having a little problem with my code in C#.
I have the same code using vb.net that is currently working perfectly. But the C# version is not
Here's what I have in vb.net:
Dim Counter As Int32 = CInt(Application("SessionCount")) lblRecords.Text += CounterHere's what I'm trying in C#:
Int32 Counter = Convert.ToInt32(Application["SessionCount"]); lblRecords.Text += (Counter);When I use this code it actually adds a number to the end of the current session number instead of adding another number to the current one on the label. I'm using this counter every time a user hit the save button.
My session variables are declared in the global.aspx. Like I said it works just fine in vb, but it does not in C.
Any help is greatly appreciated.
Thanks,
aterra
Participant
910 Points
162 Posts
Re: C# using Session
Jul 29, 2012 12:50 AM|LINK
C# will handle this differently as it assumes you are trying to concatinate the text of the counter to the tect value. Try this:
alvingeorge
Participant
925 Points
203 Posts
Re: C# using Session
Jul 29, 2012 12:53 AM|LINK
Int32 Counter = Convert.ToInt32(Application["SessionCount"]); lblRecords.Text = Convert.ToInt32(lblRecords.Text)+ Counter;senthilwaits
Contributor
3832 Points
651 Posts
Re: C# using Session
Jul 29, 2012 12:55 AM|LINK
Try this.
Int32 Counter = Convert.ToInt32(Application["SessionCount"]);
lblRecords.Text = (Convert.ToInt32(lblRecords.Text) + Counter).ToString();
Senthil Kumar Sundaram
Leo D.
Member
3 Points
30 Posts
Re: C# using Session
Jul 29, 2012 04:13 PM|LINK
This one worked out perfectly. Thank you very much!!!