473,385 Members | 1,919 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,385 software developers and data experts.

How to evaluate enum stored in Session in C# ASP.Net

Hi
I have an ASP.Net project in C# I am basing on a ASP.Net VB.Net
project. Trying to use a similar coding technique, I have the
following problem:

I have an enum declared as follows

public enum EditMode
{
Add,
Update
}

Then I store a value in a Session in various places...as an example

Session["EditMode"] = EditMode.Update;
Then, later I am tring to determine the value in an if statement

if (Session["EditMode"] == EditMode.Update)
{
....
}

yet I get an error message
"Operator '==' cannot be applied to operands of type 'object' and
'MyWebApp.MyWebFormClass.EditMode'

I tried

if (Session["EditMode"] == (object)EditMode.Update)
this seems to allow the application to build but it doesn't work

When I do an AddWatch on Session["EditMode"] it says Update as I would
think it would but I'm stuck as to how to get the if statement to
evaluate correctly

Thanks for any help....

Nov 16 '05 #1
1 4644
you need to cast the Session object back to an enum.
e.g
if (((EditMode)Session["EditMode"]) == EditMode.Update)

Ciaran
<va****@comcast.net> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
Hi
I have an ASP.Net project in C# I am basing on a ASP.Net VB.Net
project. Trying to use a similar coding technique, I have the
following problem:

I have an enum declared as follows

public enum EditMode
{
Add,
Update
}

Then I store a value in a Session in various places...as an example

Session["EditMode"] = EditMode.Update;
Then, later I am tring to determine the value in an if statement

if (Session["EditMode"] == EditMode.Update)
{
...
}

yet I get an error message
"Operator '==' cannot be applied to operands of type 'object' and
'MyWebApp.MyWebFormClass.EditMode'

I tried

if (Session["EditMode"] == (object)EditMode.Update)
this seems to allow the application to build but it doesn't work

When I do an AddWatch on Session["EditMode"] it says Update as I would
think it would but I'm stuck as to how to get the if statement to
evaluate correctly

Thanks for any help....

Nov 16 '05 #2

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

Similar topics

0
by: Luis | last post by:
I'm using a SQL Server 2000 stored procedure similar to the one below to upload data to a database. This data is collected from the user on a number of asp pages and stored in session variables...
8
by: Thomasb | last post by:
With a background in MS SQL Server programming I'm used to temporary tables. Have just started to work with DB2 ver 7 on z/OS and stumbled into the concept of GLOBAL TEMPORARY TABLE. I have...
21
by: Andreas Huber | last post by:
Hi there Spending half an hour searching through the archive I haven't found a rationale for the following behavior. using System; // note the missing Flags attribute enum Color {
6
by: Michael Isaacs | last post by:
Regarding use of enum's, I am wondering what the cost of memory is when creating the enumeration on the calling side, and then using it on the function/method side. See example below. If I...
13
by: Don | last post by:
How do I get an Enum's type using only the Enum name? e.g. Dim enumType as System.Type Dim enumName as String = "MyEnum" enumType = ???(enumName)
4
by: netnet | last post by:
Is it possible to evaluate a string as a method name? Something like this: Session = "loadFormFormACompany"; This is what I would like to do.... eval(Session+"()") Anyone have any ideas?
3
by: =?Utf-8?B?aXdkdTE1?= | last post by:
hi, im getting the powerstate of the battery usingSystemInformation.PowerState like so: PowerStatus power = SystemInformation.PowerStatus; if (power.BatteryChargeStatus ==...
7
by: Travis | last post by:
Just curious, which takes less memory? enum Months { JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC }; static const char *Months =
0
by: a573851 | last post by:
I have a very lengthy stored procedure that I just inherited. Apparently this stored proc performs poorly. I am reviewing it to see where I can add some efficiencies. I would like to know if there...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.