Can't Set Session Variable: Object Expected

In an onPageLoad() function of my initial web page, I've tried to set a global variable by saying -

Session("HelpTurnOn") = "true"

But, I get an error message that says "Object expected". I have gone to ISS Manager and configured App Options to "Enable session state". But, apparently to no avail.

Any ideas? It seems that it just won't accept any session variables.



gbmcneilAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ryerrasCommented:
did u restarted the web server?
0
gbmcneilAuthor Commented:
Negative, ryerras!
0
gbmcneilAuthor Commented:
To avoid any further embarassment I rebooted the server.

Unfortunately, the problem persists. My application just doesn't seem to like "Session" variables.

I also pulled up Web.Config file and added the following in the <system.web> node:

<system.web>
         <sessionState timeout="240" />
</system.web>

Still, no help.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

ryerrasCommented:
hmm. I am sorry. I never heard this error with the session variables. What language are you using
0
gbmcneilAuthor Commented:
Go ahead, embarass me! But, don't rub it in.

I have removed everything and still get an error.

Am I supposed to activate "Session" somehow in order for it to store variables? At present, I am still getting an error when the following line is encountered -

    Session("HelpTurnOn") = "true"

Other than this problem, I thought that ASP.NET was running okay. I've had ASP.NET up for about 6 weeks.

Quite the Order Entry System, euh?

COMPLETE WEB PAGE CODE:

<%@ Page Language="JScript" %>
<SCRIPT runat="server">
</SCRIPT>
<HTML>
<HEAD>
<TITLE>My Order Entry System</TITLE>
<script language="JScript">
function onPageLoad()
{
     Session("HelpTurnOn") = "true"
}
</script>

</HEAD>

<BODY onLoad="onPageLoad()">
    <form method="post" runat="server">
    </form>
</BODY>
</HTML>
0
ryerrasCommented:
ohh boy what are you trying to do? Isnt session a server issue. Why are you trying to access it on the client side code?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mmarinovCommented:
Hi gbmcneil,

ryerras is correct , the Session is server-side object and you can not access it through client side function
if you want to use something like this, you can set a hidden variable with this "true" value and then on postback to add this value in a session variable, but you can not do that on client side :(

Regards!
B..M
mmarinov
0
ihenryCommented:

Hello gbmcneil,

It seems your problem can be quite easy to fix. Just modify the tag <script language="JScript"> to server-side tag. Like so

<script language="JScript" runat="server">
function onPageLoad()
{
     Session("HelpTurnOn") = "true"
}
</script>
0
mmarinovCommented:
ihenry, but then how this line will executed:
<BODY onLoad="onPageLoad()">

B..M
0
gbmcneilAuthor Commented:
Okay. The truth is known. I am not an expert.

But, let me describe the problem. I have some "help baloons" built into my little application (some hints as to how to use the app). These can be a big help for about a 24 hours; after that they can be a nusance. I'll be the first to admit it.

So, I've got a menu. One item in the Help section allows the user to turn these darn things off. It's a check mark associated with the menu entry "Turn Hints On/Off". To change the appearance of the menu entry (and put a check mark in), my 3rd party menu control does a postback to codebehind. There, on the server-side I have added my little Session variable, like so: Session("HelpTurnOn") = "true". Or, "false" if they don't want to see the baloons popping up all over the place.

Well, this is great. But, the problem is that the help baloons are launched on the client side. So, I have to be able to retrieve the turn on/off variable throughout the many pages making up the application. I don't want to use a cookie except when the app is launched or exited.

Therefore, the problem comes down to accessing this variable (or some other variable) on the client side in code. What should I do?

One obvious solution would be to determine the present "gif" file (checked v. unchecked) associated with the "Turn Hints On/Off" menu entry. But, believe it or not, the 3rd party menu software people have been unable to tell me how to do this with their product.

Still open to suggestions.
 
 
   
0
ryerrasCommented:
why dont you use a hidden control and set its value on the server side. So you can access its value on the page on client side. Where do these little balloons come from. On which page do you need to access this page?. If you can put this hidden control, it should be easy enough I guess
0
gbmcneilAuthor Commented:
Yes, ryerras, I came to that conclusion and added the following code on my web page.

<%
        If Session("HelpTurnOn") = "true" Then
                Response.Write ("<INPUT Id='txtHelpTurnOn' Type='hidden' Value='true'></INPUT>")
              Else
              Response.Write ("<INPUT Id='txtHelpTurnOn' Type='hidden' Value='false'></INPUT>")
             End If
%>        

It seems to work fine! Thanks for your help.
0
ryerrasCommented:
nice to know
0
ihenryCommented:

You're right mmarinov. my apology for server and client side confusion.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.