Showing posts with label callback. Show all posts
Showing posts with label callback. Show all posts

Wednesday, March 28, 2012

Context

Hi,
how can I have something like a context for the requests that is available in the callback and timeout handler? I think sometimes it is very important to have such a context to have one handler for several different requests.
CIAO
Michael

It's already there, look at the webRequest and webResponse classes.

Can you please give me a URL where I can find more for webRequest/webResponse?

CIAO
Michael


There is unfortunately no documentation for the client-side classes for the moment. We're working on it. For the moment, you can look at the signatures of the constructors and methods in the javascript files. I know it's a little hard as they've been formatted to save space.
Hi,
ok, I got it. It is not supported by default, but I can re-write the generated code to add this feature. For more details see:http://weblogs.asp.net/mschwarz/
CIAO
Michael

Monday, March 26, 2012

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 informationis invalidfor this page and might be corrupted"error. To get the error to be thrown I usually have to vary thefrequency of my clicking, but I can reproduce it without too muchtrouble (i.e. between 2 and 30 clicks). I am able to reproduce theerror 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?

Thecode is below.

<%@dotnet.itags.org. 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 partialclass _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();
}

}

No one can help with this? Come on, one of you Microsoft gurus must be able to provide some input...


Hi,

I tried it but can't reproduce the issue.

It's caused by viewstate validation failure, you can disable it.

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" EnableViewStateMac="false"%>


Thanks for the help. Did you test it with Firefox? It's much more difficult to get IE to throw the error. I do get the error with IE, but it's much less consistent (and usually requires me to add more controls to the page). Firefox throws it pretty easily though. I actually created a video of the behavior I'm seeing with Firefox which can be seen here:

http://www.youtube.com/watch?v=EBsMRxnOtpE

(There's no audio, but I'm just running the code that I posted above, so it's not a big deal. In it, I run it with Firefox, and get it to throw the error after 20 clicks).

Unfortunately I can't disable the ViewState as in my real scenario the UpdatePanel and timer are at the top of the page checking every 60 seconds to see if the user has any new messages (internal messages to our system), and a client-side callback is used to maintain the state of the side navigation menu which consists of a Ajax Accordion control inside a Collapsible Panel.

Since the collapsing of the Panel and the selecting of Accordion panes is all done via client-side javascript, there's no good way of maintaining the state of the menu when the user is redirected to another page (or clicks a link). To solve this, I added some additional javascript that is executed whenever the user manipulates the menu, that makes a callback which stores the state of the menu in a session variable (whether it's collapsed and what Accordion pane is selected). This way when the user is redirected, or clicks on a link to another page, I have the information necessary to make the side menu look the same as it did on the previous page.

And since, these two elements are shared among all the site's pages (via a MasterPage with a UserControl for each element)....I'm not sure what to do.

Also, the error still persists even after settingEnableViewStateMac="false"in the page directive....(not sure why this thread was marked resolved/answered, I know I didn't mark it that way...)


I tried it on both IE && FF like a hundred times, but still get no exception. May be I didn't click it quickly enough?

Based on my understanding, it may be caused by different requests and responses intersect.

Can you try to disable the button upon a click and enable it again after the callback returns to avoid this?


Thanks for the help, you do have to vary the frequency of your clicking to get it to throw the error. I know it sounds bizarre but I start with a few steady clicks, not even that fast, and then increase the frequency of clicks until the error is thrown. If it hasn't thrown the error after 50 clicks, I'll reload the page and try again (Here's a better YouTube video:http://www.youtube.com/watch?v=EBsMRxnOtpE).

Disabling the button after a click might work in the test scenario but my real world app initiates a callback whenever the user manipulates the navigation menu in some way. So, hindering their ability to quickly jump from one item in the menu to another may be problematic....though callback doesn't take long, sio it's something I'll look into more...

More importantly though, I'm not sure that solves the problem. In my real app the Timer for the UpdatePanel ticks every 60 seconds, while a callback is issued every time the navigation menu is manipulated. And, when I've seen the error thrown, it appears to be thrown by the ticking of the Timer, because I've received the error after I clicked on the menu a few times, and then did nothing, and the error would only popup when the Timer executed its next Tick event...

Wednesday, March 21, 2012

ComponentArt and Extenders

So I hope I am just being stupid, and this is a easy fix. I am using the ComponentArt callback control, because for the time being at least, they are much more powerful than the UpdatePanel. I love the extenders and want to use them. So I wish to dynamically add controls and extenders. Now the scriptmanager does not register the extenders I add in a callback. So I make a new extender on the server callback, add it to me Callback control, then let is render. The scriptmanager is at a page level and the controls are being added in a component art callback. Any suggestions? Anyone else get this to work?

ThanksHi Pinger,

I'm really not sure how ComponetArt's callback control mechanism works. I know theUpdatePanelcompletely rebuilds the client side control hierarchy when it silently handles a postback (from the high level overview on the ComponentArt website, it mentions maintaining the ASP.NET viewstate, but not the "Atlas" client side control hierarchy). We've actually had a number of bugs related to this in the past because it's a little tricky to keep your behavior consistent when it's being silently torn down and recreated. You may try posting your question on their forums as they'll know a lot more about how their callback control works with "Atlas" behaviors.

Thanks,
Ted
Thanks. I did post there too, but I am just asking here too just to see if anyone else had an idea. I will however, post it I figure it out. The UpdatePanel is very nice, there are just a few things missing from it that prevent me from switching.

Extenders are looking really good, I think some work needs to be done on adding the dynamically but I am sure that will be all worked out in the end. But regarless I would tip my hat to you guys, if they let me ware one at work that is, great job so far.