Avatar of G_Hosa_Phat
G_Hosa_Phat
Flag for United States of America asked on

jQuery, JavaScript and AJAX problems with ASP.NET

Good afternoon, Experts.  I have been chasing my own tail for many, many days on this issue, and I'm hoping that someone here can point me in the right direction.  I am trying to implement an "idle timer" on my ASP.NET Web site to notify a user when their session is about to expire, and (hopefully) extend that session if the user chooses to do so.  I am building the site using Master Pages (VB), and the basic build is going just fine, but I seem to be having some issues when it comes to running certain jQuery/JavaScript/AJAX code on the pages.

I've tried using the offerings from the following pages, but none of them seem to work on my site for some reason:
http://www.techtalklive.org/ttlblog/Pages/Creating-Session-Expired-Countdown.aspx
http://pure-essence.net/2010/02/14/jquery-session-timeout-countdown/
http://code.msdn.microsoft.com/AspNetAlertSessionExpire-c230a148/sourcecode?fileId=56541&pathId=718504466

One commonality amongst these is that they are using jQuery, JavaScript and AJAX to accomplish the task of keeping the server-side session alive.  So, you might think the issue is with my browser (IE 11), but I have tried this in three different browsers (IE, Firefox and Chrome), and they all give the same basic results.  No warning dialog appears ever.  I've even tried it from multiple computers/users, and I get the same result.

But here's the real kicker: I built a plain HTML page (no ASP controls, no master page, no code-behind files) with the exact same JavaScript/JQuery/AJAX code, and the timer works exactly like it's supposed to.  The dialog pops up on screen and allows me to click "OK" to extend the session.  This leads me to believe the issue isn't with browser security settings, or any of that craziness.

What's interesting to note is that when I use the first example above with a timeout of 0 milliseconds (so the dialog should be appearing immediately), my TextBox functionality goes haywire - in IE the TAB key doesn't move me between fields, in Firefox I can't even type into any of the TextBoxes.  This seems to indicate that the dialog thinks it's showing itself, but it never actually appears on the screen.

One last little bit of info to throw out there is that there are some basic JavaScript blocks that do work correctly, such as the following:
<SCRIPT LANGUAGE="javascript">
<!-- // Javascript Email Address Encoder
var first = 'ma';
var second = 'il';
var third = 'to:';
var address = 'helpdesk';
var domain = 'example';
var ext = 'com'; 
document.write('<a href="');
document.write(first+second+third);
document.write(address);
document.write('@');
document.write(domain);
document.write('.');
document.write(ext);  
document.write('">'); 
document.write('</a>');
// -->
</script>

Open in new window

So, to sum up my question, is there possibly something in the IIS 7.5 configuration, or maybe even the web.config file that could be preventing the jQuery/JavaScript/AJAX functions from working correctly?  I feel like I've pored over these things a million times with no luck finding the culprit, and I'm about ready to start throwing things.  Thanks for all of your assistance.
ASP.NETAJAXjQuery

Avatar of undefined
Last Comment
Scott Fell

8/22/2022 - Mon
G_Hosa_Phat

ASKER
Okay, I think I may have FINALLY figured this one out.  I opened the page in Chrome and used their debugging tools (F12).  Chrome told me that it was having problems finding some of the other JavaScript files on the site, so I corrected the paths in the Master Page, and refreshed the page again.  This time, there just happened to be a delay loading the page for the first time ever, and, sure enough, the dialog box appeared for a brief second before getting covered up by the rest of the page's content.

I'm going to do some quick testing to see if I can tweak the script a little to ensure the dialog is displayed as the top-most element on the page, and hopefully I'll have my warning box working for the first time!  :)
SOLUTION
G_Hosa_Phat

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
G_Hosa_Phat

ASKER
@padas - Thank you for moving the topic.  Sorry about that, I didn't realize I had listed it under Classic ASP.

I've removed the security code in the login page that would prevent someone from an "unknown" IP address from accessing the login page and made sure that the timer is appearing on that page (under Chrome).  If you would like to take a look at it, the URL is https://www4.ciaokc.com/login.aspx.  This is a testing server I'm using while I try to get some "new" features working.

For right now, though, I'm going to go home and take a little break from all of this.  Thanks again for your help.  I'll check back in later this evening.  :)
ASKER CERTIFIED SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
G_Hosa_Phat

ASKER
Strange.  It still works in Chrome and Firefox, but for some reason the dialog refuses to appear in IE.  I've deleted my Temporary Internet Files, restarted IE (and even rebooted my PC), but something is still preventing the dialog from popping up.

As for the different versions of jQuery being loaded, I completely overlooked that, but I've tried commenting out one or the other version to see what kind of results I'd get.  I used Chrome's debugging again, and it seems that the older version has some of the functionality that was built into the template I've been working with, while v2 is necessary for the idle timer.  I'm going to try to figure out what the minified v2 is "missing" that the template is using so that I can load just the one version, but in the meantime I'm disabling the loading of the older version.

Another interesting thing that cropped up with Chrome's debugger was that, when I click the button to keep the session alive, I'm getting an IIS server error 500 for some reason.  I may end up choosing one of the other examples I identified above, but I just need to get something working.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
G_Hosa_Phat

ASKER
Okay, as strange as it is, I just tested it from another computer using IE, and the dialog appeared as it was supposed to.  I guess now my issue has something to do with my PC.  At least it seems to be working now, although I'm still a bit befuddled.

I still haven't figured out the reason for the 500 error yet, but the script seems to be working otherwise.  The URL the script is trying to GET is valid, but it apparently doesn't like something I've got going on there.  I'm going to have to do some additional testing and see if that error is a real issue or not.
G_Hosa_Phat

ASKER
It seems that I've addressed the different versions of jQuery being loaded (with some help from this page: https://www.liferay.com/community/wiki/-/wiki/Main/Several+jQuery+versions+within+Liferay).

I tested the timeout again in Chrome after reimplementing the security code (otherwise I wouldn't be able to actually log in), and I'm guessing the 500 error is preventing the actual extension of the timeout because I'm getting kicked back to the login page.  the GET is pointing to a KeepAlive.ashx Web handler in the root of the Web site (as per the first link I listed in my original post).  The ASHX file has nothing but this:
<%@ WebHandler Language="VB" CodeBehind="KeepAlive.ashx.vb" Class="KeepAlive" %>

Open in new window

, and the code-behind file (ASHX.VB) has this:
Public Class KeepAlive
	Implements IHttpHandler
	Implements IRequiresSessionState

	Public Sub ProcessRequest(context As HttpContext) Implements IHttpHandler.ProcessRequest
		context.Response.Cache.SetCacheability(HttpCacheability.NoCache)
		context.Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1))
		context.Response.Cache.SetNoStore()
		context.Response.Cache.SetNoServerCaching()
	End Sub
End Class

Open in new window

So, even if I could get it to show the dialog in IE on my machine, this particular method still wouldn't be working.  Maybe I need to try another of the examples.
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
G_Hosa_Phat

ASKER
@padas - I'm selecting a few of my posts as parts of the solution since they contain details of a few of the things that seem to have gotten it working, but giving you all the points since you were so helpful in pointing me in the right direction.  Thanks so much!
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Scott Fell

Thank you!  I'm glad it worked!