Displaying articles with tag ajax

Asp.Net: UpdatePanel concurrent requests

Posted by gabriel, Tue Aug 05 12:32:00 UTC 2008

Yesterday I was coding the infrastructure to start a thread in the server that would take too long to finish and would timeout the browser. The idea is that you could start a thread to run your long operation and let the server return the response to the browser. In order to give some feedback to the user I would query the server from time to time to check on the progress of the operation.

Everything was going great but then someone said the client wanted to be able to cancel the task running on the server. At first though it would not mess up what I had done already. The thing is that if the server was already querying the status of the task and I tried to cancel at the same time I would get an error.

Long story short, you have problem when the UpdatePanel makes multiple requests concurrently. When you do this the last request being executed wins. I looked around and found an interesting solution to this problem.

http://geekswithblogs.net/rashid/archive/2007/08/08/Asp.net-Ajax-UpdatePanel-Simultaneous-Update—-A-Remedy.aspx

What this guy did was to intercept the asyn requests and enqueue them so they are only done one at a time. Of all the things I found on the Internet this was the most interesting solution.

There is also an interesting solution in the Asp.Net site that allows you to define on among several UpdatePanel that gets precedence over the others. So, if one request is being executed and the preferred UpdatePanel trying to execute the other one is canceled. See it here

1 comment | Filed Under: Tips and Tutorials | Tags: ajax

Autocomplete has a problem with numbers

Posted by gabriel, Wed Apr 02 12:39:00 UTC 2008

When using Ajax ControlTookit Autocomplete Extender I noticed that when the value I wanted to dislplay was a number starting with 0 (zero), like 0012, this initiating zero is removed and the result would show as 12. I didn’t want this beahavior so after googling for a few minutes I found a post that had a solution.

The each string of the list that is returned to the page should have escaped double quotes before and after the string. In the following example I take a DataTable and loop through it, creating a new List in which I add the element 0 (zero) of each row sorrounding it with the escaped double quotes.



 List<string> list = new List<string>(10); 

 for (int i = 0; i < dt.Rows.Count; i++)
 {
     list.Add("\""+ dt.Rows[i][0].ToString() + "\"");
 }

 string[] arrayString = list.ToArray();


I can only assume that when the result is rendered on the page ajax library try to convert the results to numbers. Surrounding each number with escaped double quotes forces them to be treated as strings.

Thanks to my friend Allison Bertoloto who brought this problem to my attention.

0 comments | Filed Under: Tips and Tutorials | Tags: ajax