• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 744
  • Last Modified:

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.



0
gbmcneil
Asked:
gbmcneil
  • 5
  • 5
  • 2
  • +1
1 Solution
 
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 5
  • 5
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now