Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / JScript / February 2006

Tip: Looking for answers? Try searching our database.

help access session variable in javascript

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joe Befumo - 18 Feb 2006 19:55 GMT
I'm unable to access my session variables in a javascript function.  Here
are the details:

In global.asa, I have the following:

Sub Session_OnStart
   Session("TestMessage") = "Test One Two hree."
End Sub

I can set a break on the session("Test Message") line and confirm that it's
firing.

In my asp page, I have the following:

<script language="javascript">

function checkFields(theForm)
{
   alert("TestMessage");
   return false;
}

</script>

This is called by:

<FORM action="subscribe.asp" method=post id=form1 name=form1
onSubmit="return checkFields(this)">

First of all, I can't set any breaks on the javascript routine.

That aside, when configured as above, it works as expected, that is, I get
an alert message saying "TestMessage", so I know that the function is being
called. Since the function returns a value of false, subscribe.asp is not
loaded.

However, if I change that alert as follows:

alert(Session("TestMessage"));

The javascript function is apparently never called - I do not get the alert
message, and subscribe.asp is loaded.

Any ideas?
Joe Befumo - 18 Feb 2006 20:55 GMT
More info:

I changed <script language = "javascript> to

<script type="text/javascript">

Now, I get the following error:

An exception of type 'Microsoft JScript runtime error: Object expected' was
not handled.

On the line:

alert(Session("TestMessage"));

So it seems clear that it's not seeing the session object.
noonie - 25 Feb 2006 03:35 GMT
Greetings,

Response in-line...

> I'm unable to access my session variables in a javascript function.  Here
> are the details:
[quoted text clipped - 7 lines]
> I can set a break on the session("Test Message") line and confirm that it's
> firing.

The Session object is a _server-side_ object...

> In my asp page, I have the following:
>
[quoted text clipped - 7 lines]
>
> </script>

This is a _client-side_ script...

> This is called by:
>
[quoted text clipped - 11 lines]
>
> alert(Session("TestMessage"));

You are attempting to access a server-side object from the client...

> The javascript function is apparently never called - I do not get the alert
> message, and subscribe.asp is loaded.
>
>  Any ideas?

You can't do it this way!

In your ASP change where you write out the script to:-

<script type="text/javascript">

function checkFields(theForm)
{
    alert("<%=Session("TestMessage")%>");
    return false;
}

</script>

This will write the value of the server-side session variable into the
response stream whilst it is still on the server. This will appear in
the script that is streamed to the client and the literal value will
appear in your script block in the right place.

The "<%=" is an ASP shortcut for Response.Write

Signature

Regards,
Neale NOON


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.