How to check session is created or not?
-
Hi, How to check whether the session is created or not in c#? I am using like If (Session("Name") == null), but it is showing error named, object reference is not set to an object. tnx in adv.
Balasubramanian K.
-
Hi, How to check whether the session is created or not in c#? I am using like If (Session("Name") == null), but it is showing error named, object reference is not set to an object. tnx in adv.
Balasubramanian K.
-
if (Session["Name"] != null) { stName = Session["Name"].ToString(); } else { stName= ""; } something like the above We are not a Code Charity
tnx. It is working fine. If it is working with !=, why it is not working with '=='. Why it throws error?
Balasubramanian K.
-
tnx. It is working fine. If it is working with !=, why it is not working with '=='. Why it throws error?
Balasubramanian K.
It should work! Can you copy and paste your coding.
EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.
-
tnx. It is working fine. If it is working with !=, why it is not working with '=='. Why it throws error?
Balasubramanian K.
BalasubramanianK wrote:
why it is not working with '=='
if you are comparing with a string, like
if(nameStr==Session["name"] ) ;
then, for that you need to first use ToString(). like this ...if(nameStr==Session["name"].ToString()) ;
Is these you were looking for ... ? -
tnx. It is working fine. If it is working with !=, why it is not working with '=='. Why it throws error?
Balasubramanian K.
BalasubramanianK wrote:
If it is working with !=, why it is not working with '=='. Why it throws error?
Do you know what != and == means ? First one is checking inequality and second is equality checking. So if you write
if(Session["name"] == NULL)
string name = Session["name"].ToString();will throw error as you are trying to access a method in a NULL referenced object. If you change the code to
if(Session["name"] != NULL)
string name = Session["name"].ToString();, you are accessing ToString() only when Session["name"] exist. Hope it helps
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions