I have a page that uses callbacks to check if the work is complete on the server yet. It will callback to check if the work is complete and if it isn't it will wait for 15 seconds then return back to the client-side and display a pop-up that says "Do you want to continue?" and if the user picks yes it callbacks to the server again and repeats until the work is done or they choose not to continue.
This works fine in MSIE 6, but in Firefox it does not work. I have found that if I substitute the call to the pop-up (a window.open call) with a simple alert() call then code works fine in Firefox. Because of that I assuming since I'm "navigating away" by displaying the pop-up that Firefox might be canceling the callback operation. Does anyone know if this is a known bug and if so is there a work around? Is it possible that there is something wrong with my code (see below)? The pop-up uses window.opener.ProcessPopup(answer) to return control to the page. The first callback in Firefox works fine, but it is the subsequent ones that do not work (again I think it is because of the pop-up window). I have traced through the code and it goes always throughGetCallbackResult(), but does not reach the client-side script after it is has finished server-side.
Code Behind:
protected void Page_Load(object sender, EventArgs e)
{
String cbReference = Page.ClientScript.GetCallbackEventReference(this,
"arg", "GetResult", "context");
String callbackScript;
callbackScript = "function CallServer(arg, context)" +
"{ " + cbReference + "} ;";
Page.ClientScript.RegisterClientScriptBlock(GetType(),
"CallServer", callbackScript, true);
}
public void RaiseCallbackEvent(string eventArgument)
{
bool isReady = false;
int i = 0;
while (!isDSReady && i < 7) //Wait 14 seconds before showing the timeout message
{
++i;
if (AreResultsBack())
{
isReady = true;
}
else
{
Thread.Sleep(2000);
}
}
if (!isReady && i >= 2)
{
cbResult = "timeout";
}
else if (isReady)
{
cbResult = "true";
}
else
{
cbResult = "false";
}
}
public string GetCallbackResult()
{
return cbResult;
}
Client-Side:
var isReady;
var dataReady;
var popupWin;
function CallPopup()
{
if(popupWin == null || (popupWin != null && popupWin.closed))
{
popupWin = window.open('../WebMain/WaitMore.aspx','','HEIGHT=185,WIDTH=345;modal=yes');
}
}
function ProcessPopup(answer)
{
if(answer=="yes")
{
document.getElementById("<%=btnContinue.ClientID%>").disabled = true;
document.getElementById("<%=btnContinue.ClientID%>").value = "Please Wait ...";
if(!popupWin.closed)
{
popupWin.close();
}
Validate();
}
else if(answer == "no")
{
if(!popupWin.closed)
{
popupWin.close();
}
document.forms[0].__EVENTARGUMENT.value='NAVIGATETOMAIN';
document.forms[0].submit();
}
}
function GetResult(isReady)
{
if(isReady=="true")
{
dataReady = "true";
document.getElementById("<%=btnContinue.ClientID%>").disabled = false;
document.getElementById("<%=btnContinue.ClientID%>").value="Continue";
document.forms[0].__EVENTTARGET.value ="btnContinue";
document.forms[0].__EVENTARGUMENT.value='NAVIGATE';
document.forms[0].submit();
}
else if(isReady=="timeout")
{
CallPopup();
}
else
{
alert("An unexpected error has happened. We apologize for the inconvenience.");
}
}
function Validate()
{
if(dataReady !="true")
{
// show modal here and set time out.
CallServer("", "");
document.getElementById("<%=btnContinue.ClientID%>").enabled = false;
document.getElementById("<%=btnContinue.ClientID%>").value = "Please Wait ...";
return false;
}
else if(dataReady =="true")
{
return true;
}
}
This works fine in MSIE 6, but in Firefox it does not work. I have found that if I substitute the call to the pop-up (a window.open call) with a simple alert() call then code works fine in Firefox. Because of that I assuming since I'm "navigating away" by displaying the pop-up that Firefox might be canceling the callback operation. Does anyone know if this is a known bug and if so is there a work around? Is it possible that there is something wrong with my code (see below)? The pop-up uses window.opener.ProcessPopup(answer) to return control to the page. The first callback in Firefox works fine, but it is the subsequent ones that do not work (again I think it is because of the pop-up window). I have traced through the code and it goes always throughGetCallbackResult(), but does not reach the client-side script after it is has finished server-side.
Code Behind:
protected void Page_Load(object sender, EventArgs e)
{
String cbReference = Page.ClientScript.GetCallbackEventReference(this,
"arg", "GetResult", "context");
String callbackScript;
callbackScript = "function CallServer(arg, context)" +
"{ " + cbReference + "} ;";
Page.ClientScript.RegisterClientScriptBlock(GetType(),
"CallServer", callbackScript, true);
}
public void RaiseCallbackEvent(string eventArgument)
{
bool isReady = false;
int i = 0;
while (!isDSReady && i < 7) //Wait 14 seconds before showing the timeout message
{
++i;
if (AreResultsBack())
{
isReady = true;
}
else
{
Thread.Sleep(2000);
}
}
if (!isReady && i >= 2)
{
cbResult = "timeout";
}
else if (isReady)
{
cbResult = "true";
}
else
{
cbResult = "false";
}
}
public string GetCallbackResult()
{
return cbResult;
}
Client-Side:
var isReady;
var dataReady;
var popupWin;
function CallPopup()
{
if(popupWin == null || (popupWin != null && popupWin.closed))
{
popupWin = window.open('../WebMain/WaitMore.aspx','','HEIGHT=185,WIDTH=345;modal=yes');
}
}
function ProcessPopup(answer)
{
if(answer=="yes")
{
document.getElementById("<%=btnContinue.ClientID%>").disabled = true;
document.getElementById("<%=btnContinue.ClientID%>").value = "Please Wait ...";
if(!popupWin.closed)
{
popupWin.close();
}
Validate();
}
else if(answer == "no")
{
if(!popupWin.closed)
{
popupWin.close();
}
document.forms[0].__EVENTARGUMENT.value='NAVIGATETOMAIN';
document.forms[0].submit();
}
}
function GetResult(isReady)
{
if(isReady=="true")
{
dataReady = "true";
document.getElementById("<%=btnContinue.ClientID%>").disabled = false;
document.getElementById("<%=btnContinue.ClientID%>").value="Continue";
document.forms[0].__EVENTTARGET.value ="btnContinue";
document.forms[0].__EVENTARGUMENT.value='NAVIGATE';
document.forms[0].submit();
}
else if(isReady=="timeout")
{
CallPopup();
}
else
{
alert("An unexpected error has happened. We apologize for the inconvenience.");
}
}
function Validate()
{
if(dataReady !="true")
{
// show modal here and set time out.
CallServer("", "");
document.getElementById("<%=btnContinue.ClientID%>").enabled = false;
document.getElementById("<%=btnContinue.ClientID%>").value = "Please Wait ...";
return false;
}
else if(dataReady =="true")
{
return true;
}
}