473,394 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Session Variable naming conventions.

Hi,
Not sure if this is the right NG for this, but, is there a convention
for the variable names of a Session variable?

I am using .NET 2.0 in C#. I am new to all this .NET stuff, So, any
guidance appreciated.

Regards

Mar 10 '07 #1
17 5049
You can call your Session variable "Hamburger", if that "floats your boat".
What's important is that they make sense to the next developer who comes
along after you get a better job and leave...
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Control Freq" wrote:
Hi,
Not sure if this is the right NG for this, but, is there a convention
for the variable names of a Session variable?

I am using .NET 2.0 in C#. I am new to all this .NET stuff, So, any
guidance appreciated.

Regards

Mar 10 '07 #2
Control Freq wrote:
Hi,
Not sure if this is the right NG for this, but, is there a convention
for the variable names of a Session variable?

I am using .NET 2.0 in C#. I am new to all this .NET stuff, So, any
guidance appreciated.

Regards

Isn't there some formalized naming convention spec along these lines?
It has a name, which escapes me, but goes something like:

no spaces, use one string, starting with a lowercase character, then use
caps for each new word, i.e:

currentReportingQuarter

tblEmployees

rptMonthlySales
something like that...

Mar 11 '07 #3
Hi
The name is camel but it is not mandated for session variables. I use all
uppercase.
Mark
>

Isn't there some formalized naming convention spec along these lines?
It has a name, which escapes me, but goes something like:

no spaces, use one string, starting with a lowercase character, then use
caps for each new word, i.e:

currentReportingQuarter
Mar 11 '07 #4
"mark carew" <ma*******@magicwanddept.com.auwrote in message
news:4o*****************************@40tude.net...
The name is camel but it is not mandated for session variables. I use all
uppercase.
Naming conventions aren't *mandated* for anything at all, otherwise they
wouldn't be conventions...
Mar 11 '07 #5
I thought the name was Hungarian Notation.

Bjorn
Hi
The name is camel but it is not mandated for session variables. I use all
uppercase.
Mark
>>

Isn't there some formalized naming convention spec along these lines?
It has a name, which escapes me, but goes something like:

no spaces, use one string, starting with a lowercase character, then use
caps for each new word, i.e:

currentReportingQuarter

Mar 11 '07 #6
Hungarian notation is a special case of pascal notation.

With Hungarian notation, you also include information in the name of the variable,
i.e., whether it is numeric, has a decimal value, or is text...or it is whatever

That helps to identify the type of information being stored.
Hungarian notation is not favored by many programmers.

Another variation is Pascal notation, which capitalizes all words.

pascal notation : LikeThis
camel notation : likeThis
hungarian notation : txtLikeThis, rstLikeThis

Yet another one uses underscores : like_this or like_This or Like_This_and_That

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espańol : http://asp.net.do/foros/
===================================
"Bjorn Sagbakken" <bj*****@online.nowrote in message news:fO********************@telenor.com...
>I thought the name was Hungarian Notation.

Bjorn
>Hi
The name is camel but it is not mandated for session variables. I use all
uppercase.
Mark
>>>

Isn't there some formalized naming convention spec along these lines?
It has a name, which escapes me, but goes something like:

no spaces, use one string, starting with a lowercase character, then use
caps for each new word, i.e:

currentReportingQuarter


Mar 11 '07 #7
"Control Freq" <ni**@nhthomas.freeserve.co.ukwrote in message
news:11**********************@c51g2000cwc.googlegr oups.com...
Hi,
Not sure if this is the right NG for this, but, is there a convention
for the variable names of a Session variable?

I am using .NET 2.0 in C#. I am new to all this .NET stuff, So, any
guidance appreciated.
I'm not sure what you mean whan you say "session variable". Do you mean
something accessed via Session["variable"] (Session("variable") in VB.NET)?

John
Mar 11 '07 #8
John Saunders wrote:
"Control Freq" <ni**@nhthomas.freeserve.co.ukwrote in message
news:11**********************@c51g2000cwc.googlegr oups.com...
>Hi,
Not sure if this is the right NG for this, but, is there a convention
for the variable names of a Session variable?

I am using .NET 2.0 in C#. I am new to all this .NET stuff, So, any
guidance appreciated.

I'm not sure what you mean whan you say "session variable". Do you mean
something accessed via Session["variable"] (Session("variable") in VB.NET)?

John
Yes. Entries put in the Session.Item collection is generally referred to
as session variables.

--
Göran Andersson
_____
http://www.guffa.com
Mar 11 '07 #9
"Göran Andersson" <gu***@guffa.comwrote in message
news:Oe**************@TK2MSFTNGP05.phx.gbl...
John Saunders wrote:
>"Control Freq" <ni**@nhthomas.freeserve.co.ukwrote in message
news:11**********************@c51g2000cwc.googleg roups.com...
>>Hi,
Not sure if this is the right NG for this, but, is there a convention
for the variable names of a Session variable?

I am using .NET 2.0 in C#. I am new to all this .NET stuff, So, any
guidance appreciated.

I'm not sure what you mean whan you say "session variable". Do you mean
something accessed via Session["variable"] (Session("variable") in
VB.NET)?

John

Yes. Entries put in the Session.Item collection is generally referred to
as session variables.
Thanks, I was aware of that. I was asking the OP.

John
Mar 12 '07 #10
John Saunders wrote:
"Göran Andersson" <gu***@guffa.comwrote in message
news:Oe**************@TK2MSFTNGP05.phx.gbl...
>John Saunders wrote:
>>"Control Freq" <ni**@nhthomas.freeserve.co.ukwrote in message
news:11**********************@c51g2000cwc.google groups.com...
Hi,
Not sure if this is the right NG for this, but, is there a convention
for the variable names of a Session variable?

I am using .NET 2.0 in C#. I am new to all this .NET stuff, So, any
guidance appreciated.
I'm not sure what you mean whan you say "session variable". Do you mean
something accessed via Session["variable"] (Session("variable") in
VB.NET)?

John
Yes. Entries put in the Session.Item collection is generally referred to
as session variables.

Thanks, I was aware of that. I was asking the OP.

John
Ok. I got the impression from your question that you were unfamiliar
with the term, as you put quotation marks around it.

--
Göran Andersson
_____
http://www.guffa.com
Mar 12 '07 #11
On 12 Mar, 02:44, "John Saunders" <john.saunders at trizetto.com>
wrote:
"Göran Andersson" <g...@guffa.comwrote in message

news:Oe**************@TK2MSFTNGP05.phx.gbl...


John Saunders wrote:
"Control Freq" <n...@nhthomas.freeserve.co.ukwrote in message
news:11**********************@c51g2000cwc.googleg roups.com...
Hi,
Not sure if this is the right NG for this, but, is there a convention
for the variable names of a Session variable?
>I am using .NET 2.0 in C#. I am new to all this .NET stuff, So, any
guidance appreciated.
I'm not sure what you mean whan you say "session variable". Do you mean
something accessed via Session["variable"] (Session("variable") in
VB.NET)?
John
Yes. Entries put in the Session.Item collection is generally referred to
as session variables.

Thanks, I was aware of that. I was asking the OP.
Hi,
Thanks to everyone who took the time to respond to my OP.
Yes, I was referring to Session["SomeName"] = "XYZ".
I wasn't specifically meaning the style of writing the Session
Variable name, i.e using camel casing or pascal casing.
I was really wanting to know if the variable name had the Application
name, and page name embedded in it. I understand that large web apps
might use a lot of session variables, so is it a good idea to separate
them using something like "OrderEntry_DespatchDate", or
"CustomerEntry_ContactName", using the first words to specify which
screen the variable is used?

Otr, is there a better way of doing this sort of thing?

Thanks

>
John- Hide quoted text -

- Show quoted text -

Mar 12 '07 #12
JDC
On Mar 12, 2:42 pm, "Control Freq" <n...@nhthomas.freeserve.co.uk>
wrote:
Yes, I was referring to Session["SomeName"] = "XYZ".
I wasn't specifically meaning the style of writing the Session
Variable name, i.e using camel casing or pascal casing.
I was really wanting to know if the variable name had the Application
name, and page name embedded in it. I understand that large web apps
might use a lot of session variables, so is it a good idea to separate
them using something like "OrderEntry_DespatchDate", or
"CustomerEntry_ContactName", using the first words to specify which
screen the variable is used?

Otr, is there a better way of doing this sort of thing?
I think that putting the page name as part of the variable name could
cause maintenance problems in the future (or at the very least code
smells). And what happens when a variable is referenced across pages
(which is part of reason for using them)?

I suppose you could use your full namespace:
Session["MyCompany.MyApp.XYZ"], but again once you start putting stuff
like this in strings you're asking for maintenance troubles.

Here's what I tend to do:
- use the same naming convention as for classes (i.e. pascal
notation), and just use a sensible, meaningful name (just pretend
you're naming a function and you won't go far wrong).
- use a base class for my pages, and wrap session variables into a
strongly-typed property in the base class. I can provide an example if
you like.

HTH

JC

Mar 12 '07 #13
"JDC" <je**************@gmail.comwrote in message
news:11**********************@q40g2000cwq.googlegr oups.com...
smells). And what happens when a variable is referenced across pages
(which is part of reason for using them)?
Yes, I was wondering that... :-)
Mar 12 '07 #14
On Mar 12, 11:42 am, "JDC" <jeremy.d.coll...@gmail.comwrote:
On Mar 12, 2:42 pm, "Control Freq" <n...@nhthomas.freeserve.co.uk>
wrote:
Yes, I was referring to Session["SomeName"] = "XYZ".
I wasn't specifically meaning the style of writing the Session
Variable name, i.e using camel casing or pascal casing.
I was really wanting to know if the variable name had the Application
name, and page name embedded in it. I understand that large web apps
might use a lot of session variables, so is it a good idea to separate
them using something like "OrderEntry_DespatchDate", or
"CustomerEntry_ContactName", using the first words to specify which
screen the variable is used?
Otr, is there a better way of doing this sort of thing?

I think that putting the page name as part of the variable name could
cause maintenance problems in the future (or at the very least code
smells). And what happens when a variable is referenced across pages
(which is part of reason for using them)?

I suppose you could use your full namespace:
Session["MyCompany.MyApp.XYZ"], but again once you start putting stuff
like this in strings you're asking for maintenance troubles.

Here's what I tend to do:
- use the same naming convention as for classes (i.e. pascal
notation), and just use a sensible, meaningful name (just pretend
you're naming a function and you won't go far wrong).
- use a base class for my pages, and wrap session variables into a
strongly-typed property in the base class. I can provide an example if
you like.

HTH

JC
Call me lazy, but I wrote a session wrapper class that encapsulated
all the session variables in properties. Like so:

Imports System.Web.SessionState

Friend NotInheritable Class MySession

Private Const CompanySessionKey As String = "Company"

Private Shared ReadOnly Property Session As HttpSessionState
Get
Return HttpContext.Current.Session
End Get
End Property

Public Shared Property Company As String
Get
Return DirectCast(Session(CompanySessionKey), String)
End Get
Set(ByVal value As String)
Session(CompanySessionKey) = value
End Set
End Property

End Class

That way, I don't have to think about the session variable names
anywhere else in the code. No chance of typos. And the constants are
defined in one place, close to the properties that use them.

The calling code consequently looks like this:

lblCompanyName.Text = MySession.Company

Code it once, and forget about it. It's a lesson I learned from the
configuration settings stuff in ASP.NET 2.0, and it was well worth the
learning.

Hope this helps!
Mike

Mar 12 '07 #15
In IE7, if the same web app is opened on multiple tabs the session variables
are shared between the tabs - changing the value of a variable in one tab
changes it for all tabs. This is also true if the user opens a new browser
instance with Ctrl-N key sequence.

So if I have Customer A open on tab 1, and Customer B open on tab 2, how do
you store the Customer ID in a session variable without it being changed by
activity on another tab?

Bill
"Mike Hofer" <kc********@gmail.comwrote in message
news:11**********************@q40g2000cwq.googlegr oups.com...
On Mar 12, 11:42 am, "JDC" <jeremy.d.coll...@gmail.comwrote:
>On Mar 12, 2:42 pm, "Control Freq" <n...@nhthomas.freeserve.co.uk>
wrote:
Yes, I was referring to Session["SomeName"] = "XYZ".
I wasn't specifically meaning the style of writing the Session
Variable name, i.e using camel casing or pascal casing.
I was really wanting to know if the variable name had the Application
name, and page name embedded in it. I understand that large web apps
might use a lot of session variables, so is it a good idea to separate
them using something like "OrderEntry_DespatchDate", or
"CustomerEntry_ContactName", using the first words to specify which
screen the variable is used?
Otr, is there a better way of doing this sort of thing?

I think that putting the page name as part of the variable name could
cause maintenance problems in the future (or at the very least code
smells). And what happens when a variable is referenced across pages
(which is part of reason for using them)?

I suppose you could use your full namespace:
Session["MyCompany.MyApp.XYZ"], but again once you start putting stuff
like this in strings you're asking for maintenance troubles.

Here's what I tend to do:
- use the same naming convention as for classes (i.e. pascal
notation), and just use a sensible, meaningful name (just pretend
you're naming a function and you won't go far wrong).
- use a base class for my pages, and wrap session variables into a
strongly-typed property in the base class. I can provide an example if
you like.

HTH

JC

Call me lazy, but I wrote a session wrapper class that encapsulated
all the session variables in properties. Like so:

Imports System.Web.SessionState

Friend NotInheritable Class MySession

Private Const CompanySessionKey As String = "Company"

Private Shared ReadOnly Property Session As HttpSessionState
Get
Return HttpContext.Current.Session
End Get
End Property

Public Shared Property Company As String
Get
Return DirectCast(Session(CompanySessionKey), String)
End Get
Set(ByVal value As String)
Session(CompanySessionKey) = value
End Set
End Property

End Class

That way, I don't have to think about the session variable names
anywhere else in the code. No chance of typos. And the constants are
defined in one place, close to the properties that use them.

The calling code consequently looks like this:

lblCompanyName.Text = MySession.Company

Code it once, and forget about it. It's a lesson I learned from the
configuration settings stuff in ASP.NET 2.0, and it was well worth the
learning.

Hope this helps!
Mike

Mar 13 '07 #16
If you have two windows or tabs in the same session, they will be using
the same session variables. There is nothing that you can do to change that.

BillE wrote:
In IE7, if the same web app is opened on multiple tabs the session variables
are shared between the tabs - changing the value of a variable in one tab
changes it for all tabs. This is also true if the user opens a new browser
instance with Ctrl-N key sequence.

So if I have Customer A open on tab 1, and Customer B open on tab 2, how do
you store the Customer ID in a session variable without it being changed by
activity on another tab?

Bill
"Mike Hofer" <kc********@gmail.comwrote in message
news:11**********************@q40g2000cwq.googlegr oups.com...
>On Mar 12, 11:42 am, "JDC" <jeremy.d.coll...@gmail.comwrote:
>>On Mar 12, 2:42 pm, "Control Freq" <n...@nhthomas.freeserve.co.uk>
wrote:

Yes, I was referring to Session["SomeName"] = "XYZ".
I wasn't specifically meaning the style of writing the Session
Variable name, i.e using camel casing or pascal casing.
I was really wanting to know if the variable name had the Application
name, and page name embedded in it. I understand that large web apps
might use a lot of session variables, so is it a good idea to separate
them using something like "OrderEntry_DespatchDate", or
"CustomerEntry_ContactName", using the first words to specify which
screen the variable is used?
Otr, is there a better way of doing this sort of thing?
I think that putting the page name as part of the variable name could
cause maintenance problems in the future (or at the very least code
smells). And what happens when a variable is referenced across pages
(which is part of reason for using them)?

I suppose you could use your full namespace:
Session["MyCompany.MyApp.XYZ"], but again once you start putting stuff
like this in strings you're asking for maintenance troubles.

Here's what I tend to do:
- use the same naming convention as for classes (i.e. pascal
notation), and just use a sensible, meaningful name (just pretend
you're naming a function and you won't go far wrong).
- use a base class for my pages, and wrap session variables into a
strongly-typed property in the base class. I can provide an example if
you like.

HTH

JC
Call me lazy, but I wrote a session wrapper class that encapsulated
all the session variables in properties. Like so:

Imports System.Web.SessionState

Friend NotInheritable Class MySession

Private Const CompanySessionKey As String = "Company"

Private Shared ReadOnly Property Session As HttpSessionState
Get
Return HttpContext.Current.Session
End Get
End Property

Public Shared Property Company As String
Get
Return DirectCast(Session(CompanySessionKey), String)
End Get
Set(ByVal value As String)
Session(CompanySessionKey) = value
End Set
End Property

End Class

That way, I don't have to think about the session variable names
anywhere else in the code. No chance of typos. And the constants are
defined in one place, close to the properties that use them.

The calling code consequently looks like this:

lblCompanyName.Text = MySession.Company

Code it once, and forget about it. It's a lesson I learned from the
configuration settings stuff in ASP.NET 2.0, and it was well worth the
learning.

Hope this helps!
Mike


--
Göran Andersson
_____
http://www.guffa.com
Mar 13 '07 #17

"BillE" <be****@datamti.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
In IE7, if the same web app is opened on multiple tabs the session
variables are shared between the tabs - changing the value of a variable
in one tab changes it for all tabs. This is also true if the user opens a
new browser instance with Ctrl-N key sequence.

So if I have Customer A open on tab 1, and Customer B open on tab 2, how
do you store the Customer ID in a session variable without it being
changed by activity on another tab?
You don't store the customer id in a session variable.

Why do you want is stored in a Session variable?

John
Mar 13 '07 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Amit D.Shinde | last post by:
Hello Experts.. I need some help regarding cookies and session objects and also global.asa file I am creating one cookie when a user logs in on my website. The cookie stores the login name of...
7
by: cmiddlebrook | last post by:
Hi there, I keep finding myself getting inconsistent with naming conventions for things like member variables, class names etc and I just want to find something that suits me and stick to it. I...
1
by: clintonG | last post by:
Does the use of DTD, XML Schema and similar constructs adopt the use of C# naming conventions? If so how do I make the distinction of how to apply C# conventions with XML elements, attributes and...
4
by: Mark Broadbent | last post by:
stupid question time again to most of you experts but this is something that continually bothers me. I am trying to get into the habit of naming variables and controls in an assembly as per...
3
by: clintonG | last post by:
Does the use of DTD, XML Schema and similar constructs adopt the use of C# naming conventions? If so how do I make the distinction of how to apply C# conventions with XML elements, attributes and...
5
by: rastaman | last post by:
Hi all, I know of the existence of Object Naming Conventions for Visual Basic 6. Now I'm reading some books about VB .NET, but the names used for the objects are button1, picturebox1, etc. I...
4
by: Patrick | last post by:
what are the general naming conventions for vb.net controls. esp txtUserName, lblPassword, btnSubmit What are the prefixes for the controls???? I've tried to search hi and low on the net, but...
9
by: kevininstructor | last post by:
Greetings, I am in the process of creating naming conventions for VB.NET controls i.e. CheckBox -> chkShowThisOnStartup ListBoxt -> lstSomeList What I am looking for other developers...
1
by: Philipp Post | last post by:
Marcello, Not a big surprise as naming conventions have a lot to do with personal prefernces. There are a lot of threads in comp.databases and the other database groups. Just do a search for...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.