• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Coding Still

  • Home
  • About

Simultaneous async requests with multiple Update Panels

August 31, 2010 By _tasos Leave a Comment

Recently, I had to create a form that contained a list of smaller forms so that the user will submit a multiple insertion of objects. There were a lot of submit buttons and a Silverlight file uploader. Given the presence of the file uploader, all submits needed to be handled asynchronously. I thought it would be a good idea to use the update panel control for this scenario. Also, I added a trigger so when the file upload completed, a button was clicked and thus an update panel was refreshing without user interaction. Pretty neat, but soon I faced the ugly truth.

If two asynchronous requests overlapped the first was somehow killed and never completed. In many cases, while uploading 4 or 5 files, only 3 rows made it to the database! I googled a bit and I stumbled upon this article http://weblogs.asp.net/akhhttar/archive/2009/08/26/simultanious-async-requests-using-multiple-update-panel.aspx.

Unfortunately, it was the only article that mentioned this behavior. What the article suggests is that you can check if there is an asynchronous request in progress so that you can cancel the new request. Not a solution of course, but it is all I had. In my scenario, informing the user that his request cannot complete and to try again later is unacceptable, since my user is (most likely) not in front of his screen.

So I had to implement a queuing mechanism, so that all request will execute in proper order. So far it works nicely and time will tell if this solution is a keeper.

The whole process is rather simple. Every button that wants to refresh an update panel, calls the register_button(..) function instead. This function adds the button to a queue, and then calls the function that checks the queue. If there is not a pending request, a button is removed from the queue and then clicked.

var all_btns = new Array();
var position = 0;
 
var request_pending = false;
 
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_beginRequest(BeginRequestHandler);
prm.add_endRequest(EndRequestHandler);
 
function BeginRequestHandler(sender, args) {
    prm._scrollPosition = null;
}
 
function EndRequestHandler(sender, args) {
    request_pending = false;
    upload_files();
}
 
function register_button(btn_id) {
    var total_items = all_btns.length;
    all_btns[total_items] = btn_id;
    upload_files();
}
 
function upload_files() {
    if (!upload_pending) {
        if (all_btns[position]) {
            position = position + 1;
            request_pending = true;
            document.getElementById(all_btns[position - 1]).click();
        }
    }
}

After googling on this a bit more, I found a few threads at http://forums.asp.net/. You can check them also:

  • http://forums.asp.net/t/1152540.aspx
  • http://forums.asp.net/t/1108522.aspx

Filed Under: ASP.NET, JavaScript Tagged With: ASP.NET Ajax, ASP.NET Web Forms

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Categories

  • .NET Development
  • ASP.NET
  • Databases
  • Fun
  • IIS
  • JavaScript
  • Web Development

Tags

.NET Core Android ANTLR ASP.NET Ajax ASP.NET Core ASP.NET MVC ASP.NET Web Forms AWS Bouncy Castle Chartjs cli Client info detection Comic Continuous integration CSS Data backup Date handling Firebase Firefox addons Github HigLabo HTML5 Image manipulation jQuery JWT MySQL Nodejs Nuget OAuth Objectionjs OOP openssl Oracle ORM PHP Regular expressions SEO Social media SQL SQL Server UI/UX Url rewriting Videos Visual Studio Web design

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Secondary Sidebar

Archives

  • July 2020
  • March 2020
  • August 2019
  • December 2018
  • November 2018
  • February 2018
  • August 2016
  • June 2016
  • May 2016
  • February 2016
  • January 2016
  • August 2015
  • July 2015
  • October 2014
  • July 2014
  • November 2013
  • April 2013
  • February 2013
  • January 2013
  • December 2012
  • November 2012
  • August 2012
  • May 2012
  • February 2012
  • December 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • May 2011
  • April 2011
  • March 2011
  • February 2011
  • January 2011
  • December 2010
  • November 2010
  • October 2010
  • September 2010
  • August 2010
  • July 2010

Footer

Recent Posts

  • Anatomy of an Objection.js model
  • Check your RSA private and public keys
  • Round functions on the Nth digit
  • Send FCM Notifications in C#
  • Jwt Manager
  • Things around the web #5
  • Query JSON data as relational in MySQL
  • Create and sign JWT token with RS256 using the private key
  • Drop all database objects in Oracle
  • Create and deploy a Nuget package

Latest tweets

  • Things I Wished More Developers Knew About Databases https://t.co/h4gfq6NJgo #softwaredevelopment #databases May 3, 2020 12:52
  • How a Few Lines of Code Broke Lots of Packages https://t.co/p7ZSiLY5ca #javascript May 3, 2020 12:48
  • Can someone steal my IP address and use it as their own? https://t.co/HoQ7Z3BG69 January 24, 2020 13:27
  • Organizational complexity is the best predictor of bugs in a software module https://t.co/aUYn9hD4oa #softwaredevelopment January 13, 2020 08:24
  • Capitalism for people. Socialism for companies? https://t.co/zgUoPcqnix January 5, 2020 07:46
  • http://twitter.com/codingstill

Misc Links

  • George Liatsos Blog
  • Plethora Themes
  • C# / VB Converter
  • Higlabo: .NET library for mail, DropBox, Twitter & more

Connect with me

  • GitHub
  • LinkedIn
  • RSS
  • Twitter
  • Stack Overflow

Copyright © 2021 · eleven40 Pro on Genesis Framework · WordPress · Log in