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

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 PersistSessionState()
{
int MilliSecondsTimeOut = (this.Session.Timeout * 60000) - 30000;
string Script = @"
<script type='text/javascript'>
var Count=0;
var Max = 1000;
function PersistSessionState()
{
Count++;
if (Count<Max)
{
window.status = 'Link to server refreshed ' +
Count.toString()+' time(s)';
var Img = new Image(1,1);
Img.src = '/PersistSessionState.aspx';
}
}
window.setInterval('PersistSessionState()'," +
MilliSecondsTimeOut.ToString()+ @");
</script>
";

this.Page.RegisterClientScriptBlock("PersistSessio nState", 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.PersistSessionState();" to call the function
from the Page_Load event handler.
3. I added "<%@ OutputCache Location='None' VaryByParam='None' %>" 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 2710
could be caching, try:
Img.src = '/PersistSessionState.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 PersistSessionState()
{
int MilliSecondsTimeOut = (this.Session.Timeout * 60000) - 30000;
string Script = @"
<script type='text/javascript'>
var Count=0;
var Max = 1000;
function PersistSessionState()
{
Count++;
if (Count<Max)
{
window.status = 'Link to server refreshed ' +
Count.toString()+' time(s)';
var Img = new Image(1,1);
Img.src = '/PersistSessionState.aspx';
}
}
window.setInterval('PersistSessionState()'," +
MilliSecondsTimeOut.ToString()+ @");
</script>
";

this.Page.RegisterClientScriptBlock("PersistSessio nState", 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.PersistSessionState();" to call the function
from the Page_Load event handler.
3. I added "<%@ OutputCache Location='None' VaryByParam='None' %>" 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 MilliSecondsTimeOut 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 PersistSessionState()
{
int MilliSecondsTimeOut = (this.Session.Timeout * 60000) - 30000;
string Script = @"
<script type='text/javascript'>
var Count=0;
var Max = 1000;
function PersistSessionState()
{
Count++;
if (Count<Max)
{
window.status = 'Link to server refreshed ' +
Count.toString()+' time(s)';
var Img = new Image(1,1);
Img.src = '/PersistSessionState.aspx';
}
}
window.setInterval('PersistSessionState()'," +
MilliSecondsTimeOut.ToString()+ @");
</script>
";

this.Page.RegisterClientScriptBlock("PersistSessio nState", 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.PersistSessionState();" to call the function
from the Page_Load event handler.
3. I added "<%@ OutputCache Location='None' VaryByParam='None' %>" 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 = '/PersistSessionState.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 PersistSessionState()
{
int MilliSecondsTimeOut = (this.Session.Timeout * 60000) - 30000;
string Script = @"
<script type='text/javascript'>
var Count=0;
var Max = 1000;
function PersistSessionState()
{
Count++;
if (Count<Max)
{
window.status = 'Link to server refreshed ' +
Count.toString()+' time(s)';
var Img = new Image(1,1);
Img.src = '/PersistSessionState.aspx';
}
}
window.setInterval('PersistSessionState()'," +
MilliSecondsTimeOut.ToString()+ @");
</script>
";
this.Page.RegisterClientScriptBlock("PersistSessio nState", 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.PersistSessionState();" to call the function
from the Page_Load event handler.
3. I added "<%@ OutputCache Location='None' VaryByParam='None' %>" 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 = '/PersistSessionState.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.open('GET', '/PersistSessionState.aspx?' + new
Date().getTime(), true);
page_request.send(null);

Apr 18 '07 #4

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

Similar topics

7
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...
39
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...
3
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...
149
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? --...
6
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 =...
4
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...
3
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...
10
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...
6
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...
39
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...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
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.