Geeks With Blogs

Soppa Group India
iSmart Panache Inc
R Systems Internationals Ltd
Technovate eSolutions Pvt Ltd
The contents of this blog are my personal opinion and do not represent in any way the view of my employer.
These postings are provided "AS IS" with no warranties, and confer no rights.

Google PR™ - Post your Page Rank with

Narendra Tiwari

While working with AJAX we can make the web page more interactive by introducing the Fade behavior, and we can also introduce the provision of cancellation of async AJAX operation.

This is how we can leverage on usability aspect of the application.

Matt Berseth has posted a nice article to acheive this behaviour through ASP.Net AJAX, following is the source code.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head id="Head1" runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript" language="javascript">
    function onUpdating(){
        // get the update progress div
        var updateProgressDiv = $get('updateProgressDiv');
        // make it visible = '';

        //  get the gridview element       
        var gridView = $get('<%= this.gvCustomers.ClientID %>');
        // get the bounds of both the gridview and the progress div
    var gridViewBounds = Sys.UI.DomElement.getBounds(gridView);
    var updateProgressDivBounds = Sys.UI.DomElement.getBounds(updateProgressDiv);
    // do the math to figure out where to position the element (the center of the gridview)
    var x = gridViewBounds.x + Math.round(gridViewBounds.width / 2) - Math.round(updateProgressDivBounds.width / 2);
    var y = gridViewBounds.y + Math.round(gridViewBounds.height / 2) - Math.round(updateProgressDivBounds.height / 2);
    // set the progress element to this position
    Sys.UI.DomElement.setLocation (updateProgressDiv, x, y);       

    function onUpdated() {
        // get the update progress div
        var updateProgressDiv = $get('updateProgressDiv');
        // make it invisible = 'none';
    function onAbort(){
            //  abort the postback
            //  get the reference to the animation for the gridview
            var gvCustomersAnimation = $find('animation');
            //  simulate stopping by replaying the animation
            gvCustomersAnimation._postBackPending = false;

    <form id="form" runat="server">
        <asp:ScriptManager ID="scriptManager" runat="server" />
            <asp:SqlDataSource ID="sqldsCustomers" runat="server"
                SelectCommand="select customerid, companyname, contactname, contacttitle from dbo.customers"
                SelectCommandType="Text" ConnectionString="todo" />
            <p style="background-color:AliceBlue; width:95%">
                Example of using the events exposed by the PageRequestManager to cancel an async postback<br />
                Click on the column headers or the paging buttons to force an async-postback<br />
            <br />
            <asp:Label ID="lblTitle" runat="server" Text="Customers" BackColor="lightblue" Width="95%" />
            <asp:UpdatePanel ID="updatePanel" runat="server">
                    <asp:GridView ID="gvCustomers" runat="server" AllowPaging="true" AllowSorting="true"
                        PageSize="20" DataSourceID="sqldsCustomers" Width="95%">
                        <AlternatingRowStyle BackColor="aliceBlue" />
                        <HeaderStyle HorizontalAlign="Left" />
            <ajaxToolkit:UpdatePanelAnimationExtender ID="upae" BehaviorID="animation" runat="server" TargetControlID="updatePanel">
                        <Parallel duration="0">
                            <%-- place the update progress div over the gridview control --%>
                            <ScriptAction Script="onUpdating();" />
                            <%-- fade-out the GridView --%>
                            <FadeOut minimumOpacity=".5" />
                        <Parallel duration="0">
                            <%-- fade back in the GridView --%>
                            <FadeIn minimumOpacity=".5" />
                            <%--find the update progress div and place it over the gridview control--%>
                            <ScriptAction Script="onUpdated();" />
            <div id="updateProgressDiv" style="display:none; position:absolute;">
                    <tr><td align="center"><img src="Img/simple.gif" /></td></tr>
                    <tr><td align="center"><input type="button" onclick="onAbort();" value="Cancel" /></td></tr>

Posted on Wednesday, August 22, 2007 2:31 PM .Net | Back to top

Comments on this post: ASP.NET AJAX: Canceling an async postback

# re: ASP.NET AJAX: Canceling an async postback
Requesting Gravatar...
Idiot, stupid
Left by asdfasdf on Feb 27, 2008 5:21 PM

# re: ASP.NET AJAX: Canceling an async postback
Requesting Gravatar...
Khud ka code likho yaar. Kyon doosron ka code lekar apna blog bhartey ho?

Don't just blindly pick up code from others just to fill up your blog. Use your brain. Share something of your own or just close the shop down.

Nakal meoin akal chahiye. Title check karo!
Left by Narendra Tiwari on May 02, 2008 8:48 AM

# re: ASP.NET AJAX: Canceling an async postback
Requesting Gravatar...
fucking shit
Left by lol on May 24, 2008 10:02 AM

# re: ASP.NET AJAX: Canceling an async postback
Requesting Gravatar...
That was inspiring,

I like the way you wrote it .

Thanks for writing, most people don't bother.
Left by web development company on Aug 28, 2009 6:14 PM

Your comment:
 (will show your gravatar)

Copyright © Narendra Tiwari | Powered by: