Below is all the code you'll need to duplicate the problem.
DEFAULT.ASPX
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript" language="javascript"
src="javascript/Ajax.js"></script>
<script type="text/javascript" language="javascript">
setTimeout("blah();", 1000);
function clicky() {
blah();
}
function clicky2() {
var a = new Ajax('default.aspx?blah2=a', '', null);
a.returnType = 'JSON';
a.send();
}
function blah() {
var a = new Ajax('default2.aspx?blah=a', '', null);
a.returnType = 'JSON';
a.send();
setTimeout("blah();", 1000);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="updater">
</div>
<div id="updater2">
</div>
<!--<input type="button" onclick="clicky();" value="Start One Second
Timer" />-->
<asp:Button id="blahbutton" runat="server" OnClick="blah_click" Text="Do
One-Time 3 Second Call" />
<!--<input type="button" onclick="clicky2();" value="Do One-Time 3
Second Call" />-->
</form>
</body>
</html>
DEFAULT.ASPX.CS
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
Response.Write("POSTED!<br>");
//Session["hi"] = "hi"; <--- UNCOMMENT TO DUPLICATE PROBLEM
}
protected void blah_click(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(10000);
}
}
DEFAULT2.ASPX
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs"
Inherits="Default2" %>
DEFAULT2.ASPX.CS
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["blah"] != null)
{
Response.Write("var a =
document.getElementById('updater');while(a.childNo des.length >
0){a.removeChild(a.childNodes[0]);}a.appendChild(document.createTextNode('");
if (Application["a"] == null)
Response.Write(DateTime.Now.ToString());
else
Response.Write(Application["a"].ToString());
Response.Write("'));");
Response.End();
}
}
}
AJAX.JS
function Ajax(url, requestXml, callback, sendNow) {
this.url = url;
this.requestMethod = "POST";
this.requestXml = requestXml;
this.callback = callback;
this.async = true;
this.returnType = null;
this.setReturnType = __Ajax_SetReturnType;
this.errorCallback = null;
this.timeoutCallback = null;
this.request = null;
this.send = __Ajax_Send;
if(this.url && this.requestXml && this.callback && sendNow != undefined &&
sendNow)
this.send();
}
Ajax.CreateRequest = __Ajax_CreateRequest;
function __Ajax_CallbackIntercept(instance) {
if(instance.request.readyState == 4) {
if(instance.request.status && instance.request.status == 408 &&
instance.timeoutCallback)
instance.timeoutCallback(instance);
else if(instance.request.status && instance.request.status == 200) {
if(instance.returnType == null && instance.callback)
instance.callback(instance);
else if(typeof(instance.returnType) == "string")
if(instance.returnType == "JSON") {
var json = eval(instance.request.responseText);
if(instance.callback)
instance.callback(json, instance);
} else if(instance.returnType == "TEXT") {
instance.callback(instance.request.responseText, instance);
} else if(instance.callback)
instance.callback(instance.request.responseXML, instance);
else {
if(instance.replaceContents) {
while(instance.idOrDomObjectToInsertInto.childNode s.length 0)
instance.idOrDomObjectToInsertInto.removeChild(ins tance.idOrDomObjectToInsertInto.childNodes[0]);
}
instance.idOrDomObjectToInsertInto.appendChild(doc ument.createTextNode(instance.request.responseText ));
if(instance.callback)
instance.callback(instance.request.responseText);
}
} else {
if(instance.errorCallback)
instance.errorCallback(instance);
}
}
}
function __Ajax_Send() {
var instance = this;
// alert('hey');
//alert(this.request);
this.request = __Ajax_CreateRequest();
if(this.request.overrideMimeType)
this.request.overrideMimeType("text/xml");
this.request.onreadystatechange = function() {
__Ajax_CallbackIntercept(instance);
}
this.request.open(this.requestMethod, this.url, this.async);
this.request.send(this.requestXml);
}
//returnType values = "JSON", "XML", "TEXT", "HTML", "XHTML"
function __Ajax_SetReturnType(returnType, idOrDomObjectToInsertInto,
replaceContents) {
this.returnType = returnType;
this.idOrDomObjectToInsertInto = idOrDomObjectToInsertInto;
this.replaceContents = replaceContents;
if(typeof(this.idOrDomObjectToInsertInto) == "string")
this.idOrDomObjectToInsertInto =
document.getElementById(idOrDomObjectToInsertInto) ;
}
function __Ajax_CreateRequest() {
var request = null;
try {
request = new XMLHttpRequest();
} catch(e) {}
if(!request && window.ActiveXObject)
return new ActiveXObject("Microsoft.XMLHTTP");
return request;
}
"KJ" wrote:
Can you please post the relevant code?
"Shawn Sesna" <Sh********@discussions.microsoft.comwrote in message
news:9C**********************************@microsof t.com...
Greetings! I was researching AJAX to provide a solution to displaying
status
messages while a long process executed. I found several examples online
and
was able to use their code to get a quick application working. However,
when
attempting to implement the solution, the AJAX calls weren't updating the
screen like the examples were and seemed not to fire until after the long
running process had completed.
I found the only real difference between my application and the quick app
is
that I am using Session variables. I added a Session variable to the
quick
app and was able to duplicate the behavior.
The quick app I wrote is simple in nature, when the page loads, it begins
making AJAX calls and updates a div on the page with the current time
every
second. A button on the page issues a sleep command on the thread for 10
seconds. When not using a Session variable, the time continues to update
after the button is pressed. When using a session variable, the time
ceases
to update until the sleep command has expired.
Is there any way to get AJAX to work when using Session variables?