Conflict between UpdatePanel and Client-side Callback?

I posted this issue in the ASP.Net Ajax UI forum originally but never got a definitive answer:http://forums.asp.net/t/1184085.aspx

Basically, I have a Timer control outside an UpdatePanel that Ticks every second and triggers the UpdatePanel to display the current date & time.  I also have an HTML button that initiates a client-side callback, which simply counts the number of client-side callbacks executed so far, and displays the count on the page.  And finally I have a TextBox control placed outside the UpdatePanel.  The TextBox isn't used for anything, but it needs to be there for the error to be generated.

The problem is that when I repeatedly click the HTML button to initiate client-side callbacks while the Timer is ticking, I will eventually get the "The state information is invalid for this page and might be corrupted"
error.  To get the error to be thrown I usually have to vary the
frequency of my clicking, but I can reproduce it without too much
trouble (i.e. between 2 and 30 clicks).  I am able to reproduce the
error in both IE and Firefox, though it is much easier to get Firefox to throw the error (to get IE to throw the error, I had to add more server controls to the page).

A poster on the other thread said it sounded like there was a conflict between the UpdatePanel and Client-side callbacks, but couldn't provide any further information.   Is this a known issue/limitation?  Anyone know what's going on here?

The
code is below.
 

<%@ 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 id="Head1" runat="server">
<title>Testing</title>
<script type="text/javascript">
function initiateCallBack(){
doCallBack(document.getElementById("spanCallBackCount").innerHTML);
}

function callBackComplete(result){
document.getElementById("spanCallBackCount").innerHTML = result;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

<br /><br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="conditional">
<ContentTemplate>
Date & Time: <asp:Literal ID="ltrDateTime" runat="server"></asp:Literal>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
<asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick"></asp:Timer>

<br /><br />
<asp:TextBox ID="txtTest" runat="server" Text="Testing"></asp:TextBox>

<br /><br />
Call Back Count: <span id="spanCallBackCount">0</span>
<br /><br />

<input type="button" id="btnCallBack" name="btnCallBack" onclick="initiateCallBack();" value="Initiate Client-side Callback" />

</form>
</body>
</html>

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, System.Web.UI.ICallbackEventHandler
{
int callBackCount = 0;

protected void Page_Load(object sender, EventArgs e)
{
string callBackReference = Page.ClientScript.GetCallbackEventReference(this, "cnt", "callBackComplete", "context");
string callBackScript = "function doCallBack(cnt, context){" + callBackReference + "}";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "doCallBack", callBackScript, true);
}

public void RaiseCallbackEvent(string cnt)
{
callBackCount = Convert.ToInt32(cnt);
callBackCount++;
}

public string GetCallbackResult()
{
return callBackCount.ToString();
}

    protected void Timer1_Tick(object sender, EventArgs e)
{
ltrDateTime.Text = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt");

UpdatePanel1.Update();
}

}
Read More

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s