473,770 Members | 4,558 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why Doesn't This Work?

I am working on an asp.net 1.1 web app in C#. I downloaded some sample
code that is supposed to allow for me to persist session state. The
code is as follows:

private void PersistSessionS tate()
{
int MilliSecondsTim eOut = (this.Session.T imeout * 60000) - 30000;
string Script = @"
<script type='text/javascript'>
var Count=0;
var Max = 1000;
function PersistSessionS tate()
{
Count++;
if (Count<Max)
{
window.status = 'Link to server refreshed ' +
Count.toString( )+' time(s)';
var Img = new Image(1,1);
Img.src = '/PersistSessionS tate.aspx';
}
}
window.setInter val('PersistSes sionState()'," +
MilliSecondsTim eOut.ToString() + @");
</script>
";

this.Page.Regis terClientScript Block("PersistS essionState", Script);
}

When I put this into my app, I did the following:

1. I added this function to the code behind page.
2. I added the line "this.PersistSe ssionState();" to call the function
from the Page_Load event handler.
3. I added "<%@ OutputCache Location='None' VaryByParam='No ne' %>" at
the top of the aspx page, to control the client-side caching.
4. I set the session timeout value to "1" in the web.config file.

Now, when I run this, (predictably) after about thirty seconds, the
status bar reads "Link to server refreshed 1 time(s)". As you can see
in the javascript code, this fires about thirty seconds before the
Session times out. So, when I see the message and wait about 45
seconds or so after, if I try to click another page on the site, I get
a "Server Error in '/' Application - Object reference no set to an
instance of an object" message. This happens because the solution did
not work - the session expired.

So what is wrong with this solution? Why doesn't it work? How can I
fix it?

Thanks in advance for your help.

JP

Apr 18 '07 #1
3 2738
could be caching, try:
Img.src = '/PersistSessionS tate.aspx?c=' + Count;
bruce (sqlwork.com)
Joey wrote:
I am working on an asp.net 1.1 web app in C#. I downloaded some sample
code that is supposed to allow for me to persist session state. The
code is as follows:

private void PersistSessionS tate()
{
int MilliSecondsTim eOut = (this.Session.T imeout * 60000) - 30000;
string Script = @"
<script type='text/javascript'>
var Count=0;
var Max = 1000;
function PersistSessionS tate()
{
Count++;
if (Count<Max)
{
window.status = 'Link to server refreshed ' +
Count.toString( )+' time(s)';
var Img = new Image(1,1);
Img.src = '/PersistSessionS tate.aspx';
}
}
window.setInter val('PersistSes sionState()'," +
MilliSecondsTim eOut.ToString() + @");
</script>
";

this.Page.Regis terClientScript Block("PersistS essionState", Script);
}

When I put this into my app, I did the following:

1. I added this function to the code behind page.
2. I added the line "this.PersistSe ssionState();" to call the function
from the Page_Load event handler.
3. I added "<%@ OutputCache Location='None' VaryByParam='No ne' %>" at
the top of the aspx page, to control the client-side caching.
4. I set the session timeout value to "1" in the web.config file.

Now, when I run this, (predictably) after about thirty seconds, the
status bar reads "Link to server refreshed 1 time(s)". As you can see
in the javascript code, this fires about thirty seconds before the
Session times out. So, when I see the message and wait about 45
seconds or so after, if I try to click another page on the site, I get
a "Server Error in '/' Application - Object reference no set to an
instance of an object" message. This happens because the solution did
not work - the session expired.

So what is wrong with this solution? Why doesn't it work? How can I
fix it?

Thanks in advance for your help.

JP
Apr 18 '07 #2
It appears MilliSecondsTim eOut is the object not set to instance - there
doesn't seem to be any declaration for the object (in the script block), and
you are attempting to access a "ToString() " method at the end of the script.

"Joey" wrote:
I am working on an asp.net 1.1 web app in C#. I downloaded some sample
code that is supposed to allow for me to persist session state. The
code is as follows:

private void PersistSessionS tate()
{
int MilliSecondsTim eOut = (this.Session.T imeout * 60000) - 30000;
string Script = @"
<script type='text/javascript'>
var Count=0;
var Max = 1000;
function PersistSessionS tate()
{
Count++;
if (Count<Max)
{
window.status = 'Link to server refreshed ' +
Count.toString( )+' time(s)';
var Img = new Image(1,1);
Img.src = '/PersistSessionS tate.aspx';
}
}
window.setInter val('PersistSes sionState()'," +
MilliSecondsTim eOut.ToString() + @");
</script>
";

this.Page.Regis terClientScript Block("PersistS essionState", Script);
}

When I put this into my app, I did the following:

1. I added this function to the code behind page.
2. I added the line "this.PersistSe ssionState();" to call the function
from the Page_Load event handler.
3. I added "<%@ OutputCache Location='None' VaryByParam='No ne' %>" at
the top of the aspx page, to control the client-side caching.
4. I set the session timeout value to "1" in the web.config file.

Now, when I run this, (predictably) after about thirty seconds, the
status bar reads "Link to server refreshed 1 time(s)". As you can see
in the javascript code, this fires about thirty seconds before the
Session times out. So, when I see the message and wait about 45
seconds or so after, if I try to click another page on the site, I get
a "Server Error in '/' Application - Object reference no set to an
instance of an object" message. This happens because the solution did
not work - the session expired.

So what is wrong with this solution? Why doesn't it work? How can I
fix it?

Thanks in advance for your help.

JP

Apr 18 '07 #3
On Apr 18, 9:35 pm, bruce barker <nos...@nospam. comwrote:
could be caching, try:

Img.src = '/PersistSessionS tate.aspx?c=' + Count;

bruce (sqlwork.com)

Joey wrote:
I am working on an asp.net 1.1 web app in C#. I downloaded some sample
code that is supposed to allow for me to persist session state. The
code is as follows:
private void PersistSessionS tate()
{
int MilliSecondsTim eOut = (this.Session.T imeout * 60000) - 30000;
string Script = @"
<script type='text/javascript'>
var Count=0;
var Max = 1000;
function PersistSessionS tate()
{
Count++;
if (Count<Max)
{
window.status = 'Link to server refreshed ' +
Count.toString( )+' time(s)';
var Img = new Image(1,1);
Img.src = '/PersistSessionS tate.aspx';
}
}
window.setInter val('PersistSes sionState()'," +
MilliSecondsTim eOut.ToString() + @");
</script>
";
this.Page.Regis terClientScript Block("PersistS essionState", Script);
}
When I put this into my app, I did the following:
1. I added this function to the code behind page.
2. I added the line "this.PersistSe ssionState();" to call the function
from the Page_Load event handler.
3. I added "<%@ OutputCache Location='None' VaryByParam='No ne' %>" at
the top of the aspx page, to control the client-side caching.
4. I set the session timeout value to "1" in the web.config file.
Now, when I run this, (predictably) after about thirty seconds, the
status bar reads "Link to server refreshed 1 time(s)". As you can see
in the javascript code, this fires about thirty seconds before the
Session times out. So, when I see the message and wait about 45
seconds or so after, if I try to click another page on the site, I get
a "Server Error in '/' Application - Object reference no set to an
instance of an object" message. This happens because the solution did
not work - the session expired.
So what is wrong with this solution? Why doesn't it work? How can I
fix it?
Thanks in advance for your help.
JP- Hide quoted text -

- Show quoted text -
OR

Img.src = '/PersistSessionS tate.aspx?' + new Date().getTime( )

also read this article about preload via js
http://www.webreference.com/programm...pt/gr/column3/

or use XMLHTTP

var page_request = false;
page_request = new ActiveXObject(' Msxml2.XMLHTTP' );
page_request.op en('GET', '/PersistSessionS tate.aspx?' + new
Date().getTime( ), true);
page_request.se nd(null);

Apr 18 '07 #4

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

Similar topics

7
4892
by: AnnMarie | last post by:
My JavaScript Form Validation doesn't work at all in Netscape, but it works fine in IE. I made some of the suggested changes which enabled it to work in IE. I couldn't make all the changes because then it didn't work in IE. How can I enable this javascipt form validation to work in Netscape? When I use netscape, none of the alert boxes appear. It submits the form without validating anything.
39
3335
by: Mark Johnson | last post by:
It doesn't seem possible. But would the following also seem a violation of the general notions behind css? You have a DIV, say asociated with class, 'topdiv'. Inside of that you have an anchor (and whatever it contains), associated with class, 'a'. Somewhere else in, 'topdiv', there is a span or element (containing whatever), associated with class, 'b'.
3
25320
by: Matt | last post by:
I want to know if readOnly attribute doesn't work for drop down list? If I try disabled attribute, it works fine for drop down list. When I try text box, it works fine for both disabled and readOnly attribute. For example, #1 will work, but #2 doesn't work 1) <SELECT name="streetDirection" class="FormInput" DISABLED> In JavaScript, I have InputForm.streetDirection.disabled = false; 2) <SELECT name="streetDirection" class="FormInput"...
149
25207
by: Christopher Benson-Manica | last post by:
(Followups set to comp.std.c. Apologies if the crosspost is unwelcome.) strchr() is to strrchr() as strstr() is to strrstr(), but strrstr() isn't part of the standard. Why not? -- Christopher Benson-Manica | I *should* know what I'm talking about - if I ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
6
13303
by: A.M-SG | last post by:
Hi, I have an aspx page at the web server that provides PDF documents for smart client applications. Here is the code in aspx page that defines content type: Response.ContentType = "application/octet-stream"; Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileID.ToString() + ".pdf");
4
3408
by: bbp | last post by:
Hello, In an ASPX page I have a "Quit" button which make a simple redirect in code-behind. This button doesn't work no more since (I think) I moved from the framework 1.0 to 1.1 and it doesn't work only on IE! My ASPX page works in FireFox. If the button doesn't work it's because of validators (and it worked with the same code in v1.0).
3
1822
by: Dave Moore | last post by:
Hi All, Ok, here's my problem. I want to open a file and process its contents. However, because it is possible that the file may not exist, I also want to check whether the file() function is successful before attempting to process any returned data from the file() function. The php file() manual page suggests that it returns FALSE if it is unsuccessful, however this simply doesn't happen on my system. My code looks like the following: ...
10
1840
by: Sourcerer | last post by:
I wrote this very simple code in .NET VC++. I compiled it on my system, and tried to run it on my friend's computer (he doesn't have the compiler). We both have Windows XP Professional. I have .NET framework 2.0, and he had 1.0 and it didn't work; then he installed 2.0 and it still didn't work; so he tried with 2.1 and it didn't work, then 3.0 and nothing still worked. I have Intel Centrino Mobile (laptop computer), and he has Intel Pentium...
6
1944
by: Johnny Jörgensen | last post by:
I've got a usercontrol derived from a normal ComboBox that contains some special formatting code. On my main form I've got a lot of my custom comboboxes. I discovered a bug in the derived control and fixed it. But it still doesn't work for the controls already added to the form. It works fine for new instances of the control dragged from the toolbox to the form. I don't want to have to drag and drop new controls to exchange all my old...
39
5869
by: alex | last post by:
I've converted a latin1 database I have to utf8. The process has been: # mysqldump -u root -p --default-character-set=latin1 -c --insert-ignore --skip-set-charset mydb mydb.sql # iconv -f ISO-8859-1 -t UTF-8 mydb.sql mydb_utf8.sql mysqlCREATE DATABASE mydb_utf8 CHARACTER SET utf8 COLLATE utf8_general_ci;
0
9439
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10237
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10071
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8905
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7431
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3987
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2832
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.